问题
I have this code in c++ to remove directory that includes files in it:
void* hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA ffd;
hFind = FindFirstFile((fullpath+"\\" + _docname + "\\"+"*").c_str(), &ffd);
do //delete all the files in the directory
{
// check if it is a file
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
string s = (fullpath+_docname+"\\").append(ffd.cFileName);
remove(s.c_str());
}
}
while (FindNextFile(hFind, &ffd) != 0);
removeDirectory(fullpath+"\\" + _docname);
FindClose(hFind);
The problem is - the directory is actually removed only after I close the dubugger. While debugging, the directory is inaccessible, but still exists, and it make me troubles. Do you know how can I fix it to tottaly remove the folder?
回答1:
swapping the last two lines might fix this: close the handle before removing the directory
FindClose( hFind );
removeDirectory( fullpath + "\\" + _docname );
来源:https://stackoverflow.com/questions/10832251/function-to-remove-directory-removes-it-only-after-debug-finishes-c