tags:

views:

73

answers:

1

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.)

+1  A: 

Error 32 is indeed "The process cannot access the file because it is being used by another process."

Are you perhaps using FindFirstFile() to build your copy list? - that will lock the directory until FindClose().

Alex K.
"Are you perhaps using FindFirstFile()" yes
Mark
Didn't even know FindClose existed - never heard of it before.
Mark
As I say I've never used it - should I modify all existing code in the entire app to always use FindClose.
Mark
I would treat it as CloseHandle(HFILE) i.e. something you always call when your done.
Alex K.