Introduction
This is a really simple tip, but it is fairly useful if you overlook it.
So, our question today is: how to delete a folder containing zillions of files and sub folders?
Well, dah, I right-click on the folder in the Windows Explorer and select "Delete"? What kind of a silly question is that, even my 2 year old daughter randomly deletes folders from my computer when I am not looking.
Background
"Experts" might mumble, "egghh, use Shift-Del to permanently delete them, it's got to be faster since it bypasses the Recycle Bin". Well ... that is true but not the right answer.
The problem with using the Windows Explorer is that it checks the content of the folder before the delete action starts. It takes its time.
Solution
It turns out that using the Delete and even the Permanent Delete option is significantly slower than using the good old command line.
Another advantage is that it will not explode in your face as the Windows Explorer might when you push it too hard.
Ok, how to then?
The basic command is: rmdir
, which can be used like this:
rmdir /s/q E:\StuffToDelete\HugeFolder
However, that is a significant improvement when the subfolders` structure is also large. In such a case, you can get almost three times better performance using del
before the rmdir
.
The del
command will delete only the files and the rmdir
will handle the empty folders afterwards. E.g.:
del /f/s/q E:\StuffToDelete\HugeFolder > nul
rmdir /s/q E:\StuffToDelete\HugeFolder
NOTE: Do not make performance tests in parallel, since Windows will prioritize the Windows Explorer process over the rmdir
batch process and it will thus seem to be slower (in fact, it may even freeze until the shift-del process will finalize).