Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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.

(Inb4 "Windows sucks" statements, the Unix behavior does offer its complications as well, such as unclean reboots possibly resulting in the inode and data still allocated, but not reachable in any way. Thus the auto-fsck on every boot.)

share|improve this answer
Unlocker looks pretty good, actually. I'll look into adding it to our automation. Thank you. – marathon Oct 20 '11 at 0:48
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .