Page 1 of 1

Created directory is locked by explorer.exe, can't delete it

Posted: Mon Dec 15, 2008 5:57 pm
by reptor
Hi

I just ran into a weird problem I've never seen before.

I use Windows XP Home SP3. F-Secure firewall & anti-virus. Recently re-installed and should be a fairly clean system, not much programs installed.

I am developing a console program (C++) which opens a package file, reads its contents, and writes out its contents into a directory which has the basename (extension dropped) of the package file as its name.

I am using boost::filesystem::create_directory to create the directory if it doesn't exist.

Now, what happened is that after I ran the program with a certain package file as input, it created the directory just fine - empty one this time because I was just testing. But the problem is that I can't delete the directory through explorer or through console. Windows says that the directory is in use by some process.

The name of this directory is BMP2. Other package files which have different names don't have the problem, I can delete their directories just fine.

I carefully checked that this program that created the directory is not running anymore, so it can't be the one that is preventing the deletion of the directory. The program exits normally and does everything just like I want.

I checked which process is using the directory by using Process Explorer (sysinternals/microsoft), and it says that explorer.exe is using the directory. Then I close the file manager, console, visual studio, and the directory is still in use by explorer.exe and it still can't be deleted of course.

What can cause this? Is this a Windows XP bug, or perhaps caused by anti-virus program? Or by something else?

What I am going to do next is to reboot my computer and see if the problem goes away. I expect it to go away.

But anyways I would like to hear what can possibly cause this problem and if there are anything that I can do to prevent it from happening, and why it happened for that one directory named BMP2 but not for the others.

Posted: Mon Dec 15, 2008 6:13 pm
by jacmoe
Do you have any shell extensions running, like TortoiseSVN?
If so, kill the TortoiseSVNCache process.
It fixed similar problems for me.

Or it could be that your new windows installation doesn't see the file/folder permissions on your programming drive(s).

Check permissions.
If you have a GUID instead of a user, you need to take ownership again.

Let me know if I didn't explain properly. :wink:

Posted: Mon Dec 15, 2008 6:35 pm
by PolyVox
Well you could try Unlocker although personally I never got it to work (but maybe I'm just doing something wrong).

Otherwise try rebooting into safe mode?

Or maybe use a Linux live CD or some such thing to reboot and delete it from there?

Posted: Mon Dec 15, 2008 6:44 pm
by Thieum
you can close the handles directly from process explorer :
1 - search for the open directory in procexp
2 - doubleclick on the open occurrences, this will highlight the handle in the owner's process handle list
3 - right clic on the handle and close it

you may now delete the directory

This is a problem i am often encountering. it is really annoying but I haven't found a better solution than manually closing the open handles :(

Posted: Mon Dec 15, 2008 6:48 pm
by reptor
No TortoiseSVN or anything like that. By the way I stopped using TortoiseSVN because it slowed down the file manager quite a lot.

It is not a permissions issue. It is an NTFS partition. But I can create & delete other files in the same directory just fine, this one subdirectory only is problematic. And it was created as the same user that tries to delete it.

Windows clearly says that the problem is that the directory is in use, it does not complain about permissions. Or actually (I translate from Finnish) it says that there is a "shared usage problem" and that the directory "can be in use". And as I said, Process Explorer says that explorer.exe is using the directory.

I'll reboot next and then report back here if that solves the problem.

Edit: OK, I'll try first what Thieum suggests. No reboots done yet.

Posted: Mon Dec 15, 2008 6:54 pm
by reptor
When trying to close it from Process Explorer, it says "Error opening process: kahva ei kelpaa" in which "kahva ei kelpaa" is roughly said "handle is invalid". And the directory still can't be deleted.

I try as admin user next to do the same.

Edit #1: OK it worked as admin user. So I started Process Explorer as admin and did what Thieum suggests, and after that I can delete the directory normally in file manager as normal user. It is now deleted.


Edit #2: Now I ran my program by giving it the same package file as input. It created the directory but the difference this time was that I could delete the directory normally.


It is still a mystery what caused the problem. Thieum, do you have any idea what could be the reason why it happens? Do we have the same operating system? Same anti-virus?

Posted: Mon Dec 15, 2008 7:07 pm
by Thieum
It may be the same bug as the one which prevents to eject a usb drive event if all the windows are closed

Posted: Mon Dec 15, 2008 7:10 pm
by reptor
Yeah it is probably a Windows bug.

Posted: Mon Dec 15, 2008 10:58 pm
by twilight17
PolyVox wrote:Well you could try Unlocker although personally I never got it to work (but maybe I'm just doing something wrong).
Unlocker is great - sometimes the same thing happens to me, all I have to do is right click the File or Folder->Unlocker

then choose delete and hit Unlock All!

Great software ;D

Posted: Mon Dec 15, 2008 11:33 pm
by reptor
Well hopefully it won't happen again. I don't like to get programs for only getting around what seems to be an operating system bug.

It was the first time I encountered this bug and hopefully the last.

Posted: Tue Dec 16, 2008 6:25 pm
by PolyVox
twilight17 wrote:Unlocker is great - sometimes the same thing happens to me, all I have to do is right click the File or Folder->Unlocker

then choose delete and hit Unlock All!

Great software ;D
Well I'd like to agree, but actually I right clicked on the folder, selected unlocker from the context menu, and nothing happened. I was expecting a popup window or something?

Posted: Tue Dec 16, 2008 6:58 pm
by reptor
By the way, thank you people for the helpful replies :)

This is a good forum.

Posted: Tue Dec 16, 2008 10:39 pm
by twilight17
PolyVox wrote:
Well I'd like to agree, but actually I right clicked on the folder, selected unlocker from the context menu, and nothing happened. I was expecting a popup window or something?
Maybe your AV blocks Unlocker - try adding it to trusted (I have Kaspersky)