#include<windows.h>
#include<string>
#include<iostream>
usingnamespace std;
int del()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError;
string FilePath = "C:\\test\\*.*";
string FileName;
hFind = FindFirstFile( FilePath.c_str(), &FindFileData);
FileName = FindFileData.cFileName;
cout<<"FOUND: "<<FindFileData.cFileName<<endl;
while (FindNextFile(hFind, &FindFileData) != 0)
{
FileName = FindFileData.cFileName;
cout<<"FOUND: "<<FileName<<endl;
DeleteFile(FileName.c_str());//this does not work
/*remove(FileName.c_str());//this doesn't work either*/
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
cout<<"ERROR: "<<dwError<<endl;
return (-1);
}
return 0;
}
int main()
{
del();
return 0;
}
Its really annoying, what i am missing here..
EDIT: Never mind, i found out.. i forgot to put the whole adress in DeleteFile()
if anyone needs the same function he should use strcat() before DeleteFile().
Thanks for your suggestion, i will look into that some other day.
currently everything is working fine with my code except that it crashes after deleting the required files..
please take a look at my code