So if you want a windows command prompt open and its CWD is say, "C:\xyzzy\", and you attempt to delete the directory c:\xyzzy somewhere else, the delete will fail.

Most unix shells don't block deletion of the CWD like this.

We have automation that installs and deletes stuff and is always getting foiled by things like a command prompt sitting on a directory.

Is there anyway to tell windows "delete this directory, I don't care who has open files in it"?

It would be nice if this were a system setting.


No, you cannot. It's simply a difference between Unix and Windows – the former allows deletion of open files, the latter does not. There is no system setting for this. The only thing you can do is forcefully close the open handles (see Unlocker) or to entirely kill the process that has them open.

  • Unlocker looks pretty good, actually. I'll look into adding it to our automation. Thank you. – marathon Oct 20 '11 at 0:48
  • 2
    Actually, Win32 does allow deletion of open files, provided that the prior opener(s) chose to open them in FILE_SHARE_DELETE mode. – JdeBP Oct 21 '11 at 0:15
  • Which the current directory is not, unfortunately. – grawity Oct 21 '11 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.