Take the 2-minute tour ×

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.

share|improve this question
add comment

2 Answers

up vote 16 down vote accepted
rd yourdirname /s/q

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

share|improve this answer
I think the whole point of deleting empty directories is about to not delete the non-empty ones :) –  Јοеу May 25 '09 at 10:07
@Johannes, no that wasn't the point actually. I'll edit and clarify –  Assaf Lavie May 25 '09 at 17:17
add comment

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.

share|improve this answer
If you have Cygwin installed yoy can do "rm -rf dirname" –  HED May 25 '09 at 6:11
That will erase all directories, not only empty ones. –  Nathan Fellman May 25 '09 at 7:11
add comment

Your Answer


