A few months ago I received an email from Steve in Ontario:
“…I want to round out this junk cleaning by trashing empty directories as well. I have found all sorts of approaches to this, but none are elegant. I am old-school, having started as a UNIX system programmer some … 40 years ago:-) So, I like elegant solutions, and in UNIX, this would be a simple one-line piped solution … unfortunately, I’ve been stuck on Windows for the past few decades…I’m wondering if you’ve ever tackled this, and, if so, if there’s anything you can share?”
In my arrogance I thought this would be such an easy task, and coded a utility in less than an hour. Sent it off to Steve to try, and when he emailed me back I realized how tough of a problem this is.
For example, if you were looking to remove empty directories from this structure:
It would be easy to find EmptyFolder1, and EmptyFolder2. But now that they are removed, Folder2 is empty as well. This means you need to delete the deepest paths first, and work backwards.
Lots of special cases like this, and that is what makes it much more difficult than I originally thought.
Over a few weeks, Steve was gracious enough to work with me and develop a solution that worked well.
The utility is called DelEmpty.exe, a command line tool:
Here are the options:
DelEmpty.exe OPTIONS [PATH]
-f delete files of size zero
-d delete empty directories
-v verbose mode
-c confirm mode (Shows what was deleted)
-s include sub directories
-l list what would be deleted (Will not delete)
-y delete without (y/n) prompt
So, for example, if we wanted to remove all empty folders from c:\DataFolder, including sub folders – We would call it like this:
DelEmpty.exe -d -s c:\datafolder
If you wanted it to delete them without prompting you:
DelEmpty.exe -d -s -y c:\datafolder
Better yet, if we wanted to see what it would delete before taking any action:
DelEmpty.exe -d -s -l c:\datafolder
Finally, we can also remove any files that have a zero size too using the -f option:
DelEmpty.exe -d -s -y -f c:\datafolder
Please – Please be careful with this utility. It only deletes empty files and folders, but it is always possible that you have a program that *needs* those empty folders. So make sure you throughly test before using it.
It is a free utility, and you can get it from our download page:
As always, there is no spyware, adware – only IntelliAdmin Goodness.
One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools