Impossible to remove directory
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-05-11T10:20:06Z
Indexed on
2010/05/11
10:24 UTC
Read the original article
Hit count: 291
win32
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.)
© Stack Overflow or respective owner