Cannot delete folder…

I’ve been having a bad time recently. There’s a nasty bug in Windows Explorer that has been around for quite some time and the people in Microsoft just never seem to get around to fixing it. If you create a folder X, and then create a file Y in X, and then delete Y, you’ll find that you can’t delete X, even though X is empty. Explorer complains that the folder cannot be deleted because it is in use by another application. Strangely, that other application turns out to be Explorer itself. That piece of information came from a free tool called “Who Lock Me?”. Unfortunately that tool’s only solution to the problem is to kill the offending application, which is not advised when that app is your main interface to your PC.

I decided to dig deep using SysInternal’s Process Explorer to see the file handles that were persisting beyond their expected lifetime. Sure enough, there they were, belonging to the “explorer” process (and unexpectedly not belonging to any child processes of Explorer). Forcing the handles to close – and thereby possibly introducing some instability into my normally stable PC – will permit me to delete the folder.

I wondered why this was happening, but didn’t discover anything conclusive. However, I did discover something interesting. I normally delete a file by right-clicking on the icon and selecting Delete. Just before I right-click, SysInternals shows no evidence of an extra file handle, but as soon as I right-click, the extra file handle appears. Sometimes I see an extra file handle pointing to the containing folder. If I delete the file from the Command Prompt instead of Explorer, the extra file handle is not created, and I can safely delete the folder.

The same thing happens when the file is located on my USB memory stick, and the extra file handles then prevent me from ejecting the stick.

I haven’t figured out why Windows Explorer is doing this. It is a real nuisance, as this problem prevents me from rebuilding .NET installers using InstallShield. The installer compile process involves deleting previously created folders, which are locked by Windows Explorer, and so the build fails.

It’s a simple bug. I can reproduce it with ease. I can even map the problem to specific events. So this indicates that Microsoft’s unit testing for Windows Explorer is incomplete, or this failure to dispose of unnecessary file handles would never have been exposed in their front-line product. I await the fix, but all the evidence suggests I could be waiting quite a long time.

Categorised as: Uncategorized

Comment Free Zone

Comments are closed.