Take the 2-minute tour ×

I have a recurring annoying issue on one of my Windows 2008 R2 Web edition servers. The drive in question happens to be a SSD, though I doubt that is relevant.

I have a script that I run when I want to redeploy website code. The first line of the script looks like this:

rmdir C:\websites\www.mywebsite-test.com /s /q

Sometimes when that line is run, it works fine, other times the directory somehow gets corrupted. When this happens, I, as administrator, get Access Denied no matter what I do to the directory- can't open it, delete it, move it (explorer or command line), take ownership, etc. I believe the reason is the directory actually doesn't exist anymore, but something about it is hanging around making it still show up in Explorer and the Command Line. If I reboot the server, when I log back in the corrupted directory is gone. Everything is fine after that: I rerun my script, the first line responds with the directory cannot be found warning, and then it continues and deploys as normal.

This has happened the last two times I ran this script. The same script previously ran without any problems. I have another script that deploys the production code which has the same first line except without the "-test". I've never had the problem with the prod script, though it gets run less often. Both destination directories are IIS 7.5 application directories.

I'd like to know is there anything I can do to the corrupted directory when it happens so that I don't have to reboot? What is Windows doing on reboot that is finally making the directory go away? I'd like to simulate that without the reboot. Rebooting isn't a huge deal, but taking the entire server down for 60 seconds because one of my test directories is messed up is pretty annoying.

Of course a related question is why is this happening in the first place?

share|improve this question
add comment

1 Answer

The directory isn't "corrupted". You have an open handle to an item at or below that directory and until the handle is closed the delete can't complete.

You can use the SysInternals handle.exe utility to list open handles on the machine and locate the process with the open handle. If you can get that process to close the handle (or just terminate the process) you'll see the delete complete.

share|improve this answer
I used the term "corrupted" because I thought when there is an open handle it should give you "permission denied" or an "in use by process" type message and it shouldn't attempt the delete at all? The directory would still be browsable after that happens. In my case it thinks it succeeded with the delete. If there is an open handle, I would think that is a bug that Windows still tried and got as far as it did. Anyway, thanks for the link, when it happens again I will try using Handle and update this post. –  TTT Feb 11 '13 at 16:41
The original problem hasn't recurred yet, however I just tried to move a directory on a Win7 machine, and couldn't because it was locked. I just used handle for the first time to tell me what process was the culprit. Worked wonderfully! –  TTT Feb 13 '13 at 14:38
add comment

Your Answer


