May 6, 2008
2:09 am

Raymond Chen, the Microsoft coder, explains that you don’t need a whole 260KB program to automatically delete empty subdirectories. 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"

This is the long-forgotten follow-up to Performing an operation in each subdirectory of a directory tree from batch. We’re using the same technique as in that article, but pumping the result through “| sort /R” to reverse the order of the enumeration so we enumerate the directories bottom-up rather than top-down. This is important for deleting empty directories because you have to remove the subdirectories before you remove the parent.

Windows, Delete, Script, Tips

Related Posts:

No followup yet

Leave a Response

Comment Preview
« Custom Search Engine (CSE) integrated into AdSense for searchVMware Fusion 2.0 Build 89933 Beta »
Feed Icon

Subscribe via RSS or email: