Well, i tryed to delete a file via C++, But it Just wont delete it.. I tryed these 2 codes
System: Windows7 x64
Compiler: Microsoft Visual Studio 2008
:
char FileName2[512];
sprintf(m_FileName2, "D:\\SomeFolder\\SomeFile&SomeSymbols_%s3525.db",WellSomeConstChar);//Yes it has got letters/chars like & and _ and - and digits sometimes (Just if that matters)
if (remove(FileName2) !=0) {
printf("Fail delete..\n");
}
else {
printf("Success delete..\n");
}
But well none of them actually Deletes them. Note: The file exists. Because ifstream already readed it. (Now that it could be the ifstream that blocks it from deleting the file anyhow ill post that too)
1 2 3 4 5 6 7 8 9 10 11 12 13
char FileName1[256];
sprintf(FileName1, "D:\\SomeFolder\\SomeFile&SomeSymbols_%s3525.db",WellSomeConstChar);
if (!fexists(FileName1)) {
printf("File Doesnt exist.\n");
}
else {
char buffer[256];
ifstream myfile (FileName1);
while (! myfile.eof() )
{
myfile.getline (buffer,100);
//Doing something with Buffer....
}
(Now that it could be the ifstream that blocks it from deleting the file anyhow ill post that too)
Did you close the ifstream before remove()? I dont think you can delete files while theyre in use
Also the filename is different in code 1: "D:\\SomeFolder\\SomeFile&SomeSymbols_WellSomeConstChar3525.db";
in 2 & 3 youre using : "D:\\SomeFolder\\SomeFile&SomeSymbols_%s3525.db",WellSomeConstChar;