Sign in to follow this  
Prozak

Unable to delete a Folder (C++)

Recommended Posts

I coded a recursive file and folder deleter, you pass a path to this function and it deletes all files in that folder, and all sub-folders, recursively. I'm using these two functions: * remove( filename ); * RemoveDirectory( folder ); I'm having problems because all the folders I try to delete fail, it would seem that my application has a hold on them, but I don't know which function is "creating the hold", and the only functions I'm using are the two above, and these: * WIN32_FIND_DATA (struct) * FindFirstFile * FindNextFile Any help here would be dearly appreciated [wink]

Share this post


Link to post
Share on other sites
Hey Prozac,

Difficult to see what's your problem with the information that you are giving... However, first make sure that your code is correct, by pasting this one for example.
Then, I would recommend to use a program called Process Explorer, that you can find here.
Among other features, Process Explorer lets you search for a string in the process pool. Searching your directory name will show what process and thread is blocking its access. Make sure to select "View | View Handles" first. It can give you a hint on where to start searching...
Hope this helps.
Cheers,
StratBoy61

Share this post


Link to post
Share on other sites
I ran a:
* FindClose(hFile);

...on my Search handle, so that no handles used in the search would be open, but still it doesn't let me delete the folders. What other handles could I have dangling?

Share this post


Link to post
Share on other sites
Try using a shell extension tool called "Unlocker", this will give you detailed information about the locks for a file (and unlock it as well).

Edit: BTW have you checked so that your application doesn't have the current folder set to the one you're deleting?
GerCurrentDirectory != RemoveDirectory


Share this post


Link to post
Share on other sites
Thank you all, I was able to find where the problem was.

Apparently I was recycling a handle that hadn't yet been released. This caused for the original handle value never to be released, and as this handle was part of the FileFind class, I always had an active handle pointing to the folder I wanted to delete.

All fixed now, Rating++ [wink]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this