Filed under: Utilities, Windows, Microsoft, Freeware, How-Tos
Automatically delete empty subdirectories with one-line batch file
Deleting empty subdirectories seems like something Windows ought to do automatically, but for some reason that function just isn't included as part of the OS. Luckily, you don't need to download a utility to do it; instead, you can create a single line batch file that will do exactly what you're looking for:
for /f "usebackq" %%d in ("dir /ad/b/s | sort /R") do rd "%%d"
Raymond Chen, the venerable Microsoft coder, explains how this works. Basically, it uses a trick to enumerate the directories in reverse order. Since you can't delete a directory that contains data (including other directories) the only way to automate deleting directories is to start at the very bottom of the tree and work your way up.
Get a WordPress.com Blog
With Halloween fast approaching, it's a great time to get in some practice defending your territory against zombies. In Graveyard Shift, you take aim at zombies and other creepy-crawlies, blasting them into splatters of cartoony green guts. It's a casual first-person shooter, and it's very easy to get the hang of - use the mouse to aim, click to fire. Graveyard Shift has at least 15 levels, and it might even have some secret stages I haven't unlocked yet.
They key to getting good at Graveyard Shift is learning to use ...

Reader Comments (Page 1 of 1)
Jeebus said 1:26PM on 5-05-2008
RD /S works for me.
Reply
hazard said 1:05AM on 5-06-2008
I presume this is for a deltree operation that works on all flavours of Windows cause it's certainly not required for WinXP as Jeebus has pointed out rd /s or rmdir /s do this already ...
Reply
Mark said 11:29AM on 5-06-2008
Uh guys, doing that will delete everything. Files and all. This is just to delete empty subdirectories and leave your files alone.
dsfdsfsdf said 11:26PM on 5-07-2008
"Deleting empty subdirectories seems like something Windows ought to do automatically"
-> Huh? I'm pretty glad that it does not...
Reply
Hans said 6:46AM on 7-01-2008
This looks handy, but how I have another problem. I do scheduled exports from a system and it mostly dumps empty files into a folder. How do I do to delete zero (null) sized files within that directory so that only files that contain data are spared?
Reply