Unable to delete a Folder (C++)

Started by
3 comments, last by Prozak 17 years, 4 months ago
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]
Advertisement
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
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?
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


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]

This topic is closed to new replies.

Advertisement