Thursday, 22 March 2012

Fastest Way to Delete a Directory In Windows

I had a load of large directories (several GBs) which I needed to delete so that I could meet the minimum free space requirement for Windows to run the defragmentation tool.  Unfortunately, Windows Explorer is unusably slow for this as it first scans the whole directory so that it can show the estimate and then copies everything into the recycle bin or not if the directory is too big.

Below is some batch script to delete a directory very fast.  The code is on stack overflow here where the commenter Hugo bench marked it at 3 times faster than rmdir which itself is a hell of a lot faster than deletion via Windows Explorer.


rem to use, drop in your c:/windows/system32 directory for this to be usable anywhere
rem in then command line type 'bestrmdir MyDirectory' to delete MyDirectory
del /f/s/q %1 > nul 
rmdir /s/q %1

No comments: