std::wstring inxmpath ( L"folder" );
HANDLE hFind;
BOOL bContinue = TRUE;
WIN32_FIND_DATA data;
hFind = FindFirstFile(inxmpath.c_str(), &data);
// If we have no error, loop through the files in this dir
int counter = 0;
while (hFind && bContinue) {
std::wstring filename(data.cFileName);
std::string fullpath = "folder/";
fullpath += (const char* )filename.c_str();
if(remove(fullpath.c_str())!=0) return error;
bContinue = FindNextFile(hFind, &data);
counter++;
}
FindClose(hFind); // Free the dir
I don’t understand why it doesn’t work, I think it has something to do with the conversions between wstring and string however I’m not sure about that. I have a folder which has some .txt files, I need to delete all of them using C++. There are no folders in it nothing. How hard can this be?
Secondly, according to MSDN about the
FindFirstFilefunction:“Searches a directory for a file or subdirectory with a name that
matches a specific name (or partial name if wildcards are used).”
I cannot see a wildcard in your input string, so I can only guess that
FindFirstFilewill look for files named"folder"in the current execution directory.Try looking for
"folder\\*".