RemoveDirectory() fails
RemoveDirectory() fails
(OP)
Hi, I can't figure out why, but whenever I use RemoveDirectory() to delete an empty directory it fails with "The process cannot access the file because it is being used by another process", but I can delete the directory by hand through Windows Explorer. Why can Windows Explorer delete it, but not RemoveDirectory() when I use it in my program?
RE: RemoveDirectory() fails
(Then again if this is on XP, you might be seeing the file locking bug that's common, but Microsoft hasn't bothered to fix. This is why I run Unlocker, too. You wouldn't believe the number of times that I've tried to delete files, but had to force remove a file lock on them made by Explorer.exe.)
RE: RemoveDirectory() fails
ProcessExplorer doesn't show anything using that handle.
The strange thing is that Windows Explorer has no problems deleting the directory. What could Explorer be doing that I'm not?
I was having a similar problem with DeleteFile() where it said "Access Denied", but then I found out it was because the file was ReadOnly.
When I look at the directory attributes, it's set to half ReadOnly (or whatever you call it?). The checkbox is all green instead of having a checkmark in it. Every time I uncheck it, Apply & OK, it keeps going back to the all green state. Could that have something to do with it?
RE: RemoveDirectory() fails
I had a bug in my DirectoryIterator class where it was calling FindFirstFile()..., but I forgot to call FindClose(). Doh!
Never trust code you wrote several years ago.