Why does mkdir occasionally give Access Denied?

2019-02-23 19:24发布

问题:

I have BAT scripts which are nothing tricky and work fine on XP. But on Win 7, about 1 in 5 executions of mkdir following rmdir give a mystery Access Denied. E.g.

S:\TLIB importing\! Curtains\2 To process>rmdir temp3allout /s /q

S:\TLIB importing\! Curtains\2 To process>mkdir temp3allout
Access is denied.

After this, when I try in Explorer, it has no problem making that directory. Running thatBAT again usually succeeds.

Any idea what's going on here?

Win XP disc was a regular 2Gb drive. Win 7 disc is a 2Gb Intel RST RAID1 array with caching and flushing disabled http://i.imgur.com/Ohqkg2t.png .

回答1:

This happens when the file system hasn't finished deleting the directory yet.

Sometimes this will happen synchronously, i.e., before the rmdir command completes, but sometimes there will be a very short but nonzero delay. (In XP it was always synchronous, IIRC.)

If possible, avoid deleting and immediately recreating directories; if you can't avoid it, you'll need to detect the failure and retry.

You should probably also test and if necessary retry the rmdir; sometimes rmdir runs into the same problem and fails to delete the entire directory tree.



回答2:

Because that directory or file in that directory is open in some editor,first you have to close that file/directory from editor and then try.

These error usually comes when we create some directory and then delete it,but it is partially deleted and we create new directory with same name.



标签: windows-7 cmd