Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RemoveDirectory() fails

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
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?
 
Which process is holding the file reference? Something like a Process Explorer or Unlocker might be a useful tool to find that out.

(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.)
 
Yes, I'm using XP Home SP2.

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?
 
Nevermind... I fixed it.
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. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top