views:

667

answers:

2

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...)

Clarification:

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.

+6  A: 
rd yourdirname /s/q

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

kenj0418
I think the whole point of deleting _empty_ directories is about to _not_ delete the non-empty ones :)
Joey
@Johannes, no that wasn't the point actually. I'll edit and clarify
Assaf Lavie
+2  A: 

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.

Nathan Fellman
If you have Cygwin installed yoy can do "rm -rf dirname"
HED
That will erase *all* directories, not only empty ones.
Nathan Fellman