Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does mkdir occasionally give Access Denied?

Tags:

cmd

windows-7

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 .

like image 782
ChrisJJ Avatar asked Aug 19 '14 23:08

ChrisJJ


1 Answers

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.

like image 77
Harry Johnston Avatar answered Sep 22 '22 05:09

Harry Johnston