Joystiq has your stash of criminally complete GTA IV news!
AOL Tech

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.

Related Headlines

Reader Comments (Page 1 of 1)

Add your comments

Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

When you enter your name and email address, you'll be sent a link to confirm your comment, and a password. To leave another comment, just use that password.

To create a live link, simply type the URL (including http://) or email address and we will make it a live link for you. You can put up to 3 URLs in your comments. Line breaks and paragraphs are automatically converted — no need to use <p> or <br> tags.

New Users

Current Users

Download Squad Features


Geeking out on the squadcast. Tune in and then tune out.

View Posts By

  • Windows Only
  • Mac Only
  • Linux Only
Categories
Audio (803)
Beta (282)
Blogging (662)
Business (1368)
Design (789)
Developer (935)
E-mail (501)
Finance (124)
Fun (1681)
Games (531)
Internet (4569)
Kids (129)
Office (491)
OS Updates (554)
P2P (170)
Photo (454)
Podcasting (169)
Productivity (1279)
Search (204)
Security (521)
Social Software (1011)
Text (441)
Troubleshooting (45)
Utilities (1815)
Video (973)
VoIP (131)
web 2.0 (583)
Web services (3205)
Companies
Adobe (177)
AOL (43)
Apache Foundation (1)
Apple (466)
Canonical (29)
Google (1276)
IBM (29)
Microsoft (1277)
Mozilla (431)
Novell (16)
OpenOffice.org (41)
PalmSource (11)
Red Hat (18)
Symantec (14)
Yahoo! (343)
License
Commercial (659)
Shareware (193)
Freeware (1891)
Open Source (867)
Misc
Podcasts (13)
Features (371)
Hardware (170)
News (1099)
Holiday Gift Guide (15)
Platforms
Windows (3512)
Windows Mobile (412)
BlackBerry (40)
Macintosh (2033)
iPhone (74)
Linux (1538)
Unix (74)
Palm (178)
Symbian (120)
Columns
Ask DLS (10)
Analysis (24)
Browser Tips (277)
DLS Podcast (5)
Googleholic (179)
How-Tos (94)
DLS Interviews (19)
Design Tips (15)
Mobile Minute (114)
Mods (69)
Time-Wasters (362)
Weekend Review (30)
Imaging Tips (34)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Sponsored Links

Advertise with Download Squad

Most Commented On (60 days)

Recent Comments

Urlesque Headlines

BloggingStocks Tech Coverage

More from AOL Money and Finance

More Tech Coverage

Weblogs, Inc. Network

Other Weblogs Inc. Network blogs you might be interested in: