Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

RemoveDirectory() fails

RemoveDirectory() fails

RemoveDirectory() fails

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

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

RE: RemoveDirectory() fails

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?

RE: RemoveDirectory() fails

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.  winky smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close