Download the new Switched app for your iPhone

Skip to Content

Free Switched iPhone app - try it now!
AOL Tech

Filed under: Utilities, Windows, Microsoft, Freeware, How-Tos

Automatically delete empty subdirectories with one-line batch file

rdempty.bat batch fileDeleting 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.

jobs & resumes
Mac Support Technician

Kerdan - Cambridge, MA (2 weeks ago)

See More Relevant Jobs ›

Reader Comments (Page 1 of 1)

Featured Time Waster

Level Up! A platform-hopping RPG Time-Waster

I don't know if this is a labor of love or merely the brainchild of four very gifted games designers, but Level Up is a really weird mash-up of gaming elements that you have probably never seen in a Flash game before. Let's start with the premise itself: Groundhog Day meets Memento. The game experience revolves around 'days': you explore the world and the clock slowly ticks towards the evening. You bounce around picking up gems and talking to the denizens of 'Level Upland'. Eventually you feel tired and head back to ...

View more Time Wasters


Follow us on Twitter!

More Tech Coverage

Joystiq

TUAW

DailyFinance

Autoblog

Urlesque

Engadget

WoW

Switched.com

FanHouse