How to Delete Empty Folders - FREE!
While performing a disk cleanup recently, I had cause to locate and delete any empty folders under a root folder. I knew there had to be a batch file command to accomplish this, but I couldn’t for the life of me remember what it was!
Enter Google.
five minutes of some keyword searching with surgical precision and piecing together commands yielded my solution.
DIR /AD/B/S | SORT > FOLDERLIST.BAT
How It Works.
The Dir command is the familiar directory list command that comes standard with all versions of Windows since 95. The magic is in the switches:
/A Displays files with specified attributes.
When applied to the “D” attribute, it returns directories
/B Uses bare format (no heading information or summary).
/S Displays files in specified directory and all subdirectories.
SORT is an often overlooked command for, you guessed it, sorting. Here, the results of the Dir command are piped (”|”) into the SORT command as input. The result of the SORT command is then redirected from the command prompt to a file called FOLDERLIST.BAT.
Kick it up a notch.
Now that you’ve created this list, say you want to automate the deletion of each entry in the list. This is where pumping the output to a “.bat” file comes in. Open the bat file in textpad, or notepad, or your text editor
For example:
Typing:
DIR /AD/B/S | SORT > FOLDERLIST.BAT
in my C:\Program Files\Microsoft Visual Studio 8\VC folder yields the following results:

Next, open the file in a text editor, word, or open office and replace the beginning of each line with the RD command followed by a space and a single quote. Like so:

This should give you the following:

Notice how each line now begins with “RD “” This is the old DOS Remove Directory command. Don’t worry, it only removes empty directories. But you still need to add an ending quote to each line. This is where Word or Open Office is handy. You can do another search and replace, but this time search for “^p” (new paragraph) and replace with ““^p” (end quote and new paragraph).
Save the file, and you’re all done except the double clicking.
Related Posts - The 3 Most Important Questions You Should Ask About Each Bug You Find. I stumbled upon (quite literally) an article by Tom Van Vleck titled Three Questions About Each Bug You Find today, and thought I would share it: "The key idea behind...
- 10 Useful, Often Overlooked HTML Tags. Pop quiz: When would you use the <wbr> tag, and what does it do? Yeah, I had no idea either. In fact, I had never even seen this tag before,...
- Annoying "next message" behavior in Thunderbird, and how to stop it! I love the Thunderbird email client. I use the portable version on my thumb drive, but one thing has always bugged the hell out of me when I use it:...
- Microsoft FxCop doesn't like Microsoft generated code! The other day I thought it might be nice to "do the right thing" and give my code a run against Microsoft's FxCop. I ran it right out of the...
- Google Chrome: the OS. Google announced last Tuesday that it has its sights on dethroning Microsoft as desktop OS king: "The new operating system, announced late Tuesday night on Google's Web site, will be...
Related Websites - Weight Loss Tips and Tricks When it comes to losing weight, you probably know the drill. Burn more calories than you consume, eat healthy, and be healthy and the results will happen. Most diets and weight loss plans do not have much substance which is why dieting in general is far from healthy for you.......
- The Lab Today just release "The Lab". The Lab is something simple, it is a place where all the scripts from this site can be found. Is a simple dir listing with the script description and use full links. I used a Php script to do the files listing and sorting by......
- Anti Aging Makeup Tricks and Tips pt 2 There are makeup tricks and tips that you can apply to melt away the years and start feeling and looking young and beautiful again. Here are some of my favorite makeup tricks and tips for just that purpose. Rosy Lip Hues Rosy lip hue is perfect because it gives you......
- Wordpress Backup Wordpress Backup is an essential plugin for all Wordpress blog administrators by the Blog Traffic Exchange. It performs regular backups of your upload (images) current theme, and plugin directories. Backup files are available for download and optionally emailed to a specified email. Don't get caught without a recent backup of......
- Anti Aging Makeup Tricks and Tips pt 1 There are all kinds of makeup tricks and tips out there, but choosing the right ones for your own personal needs is something that you need to figure out. Here are some unique makeup tricks and tips that are anti-aging in nature. What I meant to say is that there......
