I need to delete one folder containing other folders and files inside. I tried del
and rmdir
commands but sometimes they fail with some error lines: [PATH]: The directory isn't empty.
Is there any good alternative?
command linewindows
I need to delete one folder containing other folders and files inside. I tried del
and rmdir
commands but sometimes they fail with some error lines: [PATH]: The directory isn't empty.
Is there any good alternative?
Best Answer
This happens to me a lot with my automated build scripts.
I guess the reason might be some application that has a file open in that directory with "share delete". I.e. the application allows a deletion of the file (which is why I figure the DeleteFile call doesn't fail), but the file will only disappear after said application has closed it's handle.
That means the file might still be there when the
rmdir
command tries to delete the folder, hence the error message. Soon after that, said application will close it's handle, the file will disappear, and when you inspect the folder to see which filermdir
was talking about it will be empty.At least that's my theory.
The workaround proposed by Harry Johnston looks good. Only I would insert a pause in between the
rmdir
commands. Of course Windows has no easily scriptable "pause" command (correction: ancient Windows versions don't, newer have - see comments). But if seconds granularity is enough one can useping
to create a pause:So in total: