Impossible to remove directory
- by Mark
Evidently I've never had to delete a directory using win32 sdk before, because its apparently an impossible task. I've tried anything and everything - RemoveDirectory,
SHFileOperation with FO_DELETE, etc.
Currently I call CreateDirectory in one thread, start another thread, copy some files to this directory in the new thread, then delete all the files in the directory in the new thread, and then back in the original thread that created the directory, try to delete the now empty directory and it fails. The directory really and truly is empty when I try to delete it, but it makes no difference. The whole thread aspect is irrelevant I think because at one point everything was in one thread and it didn't work. I'm currently setting a SecurityAttributes structure on CreateDirectory to grant access to everyone, but it makes no difference. RemoveDirectory in the past has returned '32' on GetLastError, which I believe is Sharing violation.
But even if I just try to delete the empty directory from the command line, it refuses saying, "The process cannot access the file because it is being used by another process."
until I shut down the entire application that created the directory. (Note: the directory is created in GetTempPath.)