Tutorial :Fastest way to delete a tree of directories in batch file


I need to write a batch file that received a directory that contains a huge number of empty sub-directories and deletes them all.

What's the fastest way of doing this? (by fast I mean not like what Windows Explorer does when you try to delete such a directory...)


I'm not trying to delete only empty directories. It just so happens that this dir I'm trying to delete is mostly empty sub-dirs.


rd yourdirname /s/q  

Will do the job regardless of whether they are empty or not.


I'm not sure if I understood the question. If you just want to delete the tree then you can just use rd /s. However, if you only want to delete empty directories, then you can do the following using Cygwin.

find -type d -empty | xargs rmdir  

The standard IT build where I work has Cygwin installed, and I've used this more than once.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »