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 - Free Firewall Recommendations (Protect Yourself Online With These Free Firewalls) If your home computer is connected to the internet, or to other computers that are connected to the internet - you need a firewall. It's as simple as that. Hackers...
- 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...
- How To Control Disk Thrash From ccmexec.exe (SMS Agent). Today started like any other day at work. I sat down, logged into my PC and was greeted by the thrashing sound of my hard drive. I've come to realize...
- Arraylist and generics don't mix with IEnumerable(Of T).GetEnumerator. The other day I was writing an in-house tool to assist in some upgrades we were performing on client installations. This tool was supposed to perform its operations on a...
- Window.scrollTo Fails Under OVERFLOW-Y: auto Style. I was trying to subclass a Web Treeview control for my own evil purposes and ran into a sticky problem - scrollTo not working! Just for background, my evil purpose...
Related Websites - Skateboarding Tricks There are a wide variety of different skateboarding tricks that you can try to perform out there. They range significantly in terms of level of difficulty. There are a wide variety of different tricks that you can learn, depending on what your own skateboarding skills are and what types of......
- 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.......
- 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......
- Solaris one liners http://www.unixguide.net/sun/sunoneliners.shtml Unix/Solaris: One-Liners Source: http://www.kevlo.com/~ebs/unix_commands.txt Listed here are a bunch of unix commands. --> change file date stamp touch –t 199906042020 filename --> move partitions ufsdump 0f - /dev/rdsk/c0t0s0s0 | (cd /home; ufsrestore xv -) --> lay down file system with 1% minfree and inode density newfs –m1 –i81920 /dev/rdsk/c0t0d0s0......
- Bash Tips & Tricks http://www.ukuug.org/events/linux2003/papers/bash_tips/ http://www.gbdirect.co.uk/ Power Shell Usage Bash Tips & Tricks Simon Myers simon.myers@gbdirect.co.uk UKUUG Linux 2003 Conference • August 2003 http://www.ukuug.org/events/linux2003/ This view lists all the slides from the talk in a continuous format. There is a PDF version available, suitable for printing on A4 paper. The slides are also......
