Apr 13, 2022

Apr 13, 2022

How to Delete All Empty folders on any directory with a simple click

Productivity

Productivity

yellow sticky notes beside white apple magic mouse and white apple keyboard
yellow sticky notes beside white apple magic mouse and white apple keyboard

Apr 13, 2022

Apr 13, 2022

How to Delete All Empty folders on any directory with a simple click

Productivity

Productivity

This utility will allow you to create a .bat file that scans a desired location, and deletes every empty folder. Especially useful when you have tons of folders that don't get used at the end of a project, or just want to tidy up.

1. Intro

This is a fun one. I found a utility, not long ago, to delete all the empty folders and subfolders within a directory. I think it's super useful to clean up those complicated project folder structures that end up with more empty folders than used ones. Other times, it's just overall cleanup when necessary.

The tool in question is aptly called Delempty, and was created by *Skrommel* with AutoHotKey. With it you can open certain folders and it will scan the items inside, letting you pick those with 0 files or 0 bytes. This alone is a great (and safe!) way to get rid of those pesky files. If you just want the tool this form, get it here:

DelEmpty

HOWEVER, we can s p i c e things up a bit and make this tool automatic, and also give it a powerful shortcut that will let us right click anywhere and use the tool in the current folder and subfolders.

❗ Just as a warning, this tool deals with deleting empty folders. Not only that, but it can do so automatically and with no Undo button. I use it all the time and it has never caused any issues, but since I'm introducing it here, I feel obligated to warn you and encourage you to always back up your work in case something goes wrong.


2. How to ‘install’ the utility

a. Automatically deleting all empty folders

What we need to do now, is take this utility and configure it to do what we want, automatically.

For this, we can use a .bat file, and point it to the Delempty.exe tool, along with some indications on what we want it to do.

I've created two separate zip files containing different settings for the tool (click to download):


Option A: Delete Empty Folders OPTION A.zip

Option B: Delete Empty Folders OPTION B.zip

Will delete empty folders and directories

Will delete empty folders and directories

Will include subfolders

Will include subfolders

Will list all folders about to be deleted

Will not list all folders to be deleted

Will ask for confirmation before deleting

Will delete without confirmation


Personally, I use Option B. But I'm also a maniac, and I think you should start with Option B just to play around. To switch options just copy replace one .bat file with the other.

You can extract the zip file, and place the **folder on your C:/Program Files directory, so that it will live here:

📂 C:/Program Files/Delete Empty Folders


The way I've set it up, the Delete Empty Folders.bat script will look for the Delempty.exe tool in this directory, tell it which folder you're pointing at, and execute it with some options written in the form of letters at the end of the script. Nothing that you need to know, but it's a pretty basic setup so if you ever dig in, you'll understand right away.

✅ Now you should be able to drag any folder into the .bat file, and it will delete all the empty folders inside and those within!


b. Creating the mother-of-all shortcuts

In order to create this shortcut so that we can execute the tool by right clicking inside any folder, we're going to add it through the Windows Registry editor. Press the Win+R key, and type regedit on the small window that pop up. Then, press enter.

Inside here, you want to navigate to the following folder:

📂 Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\

Then, right click on the shell folder to create a New Key (looks like a folder), and call it "Delete Empty Folders".


Once again, right click on the new Delete Empty Folders key you just created, and create a new key underneath, and call it "command".

Click on the command key, and on the window to the right you should see a default key. Double click on it, and type (or copy/paste) the following as the value:

🔑 C:\Program Files\Delete Empty Folders\Delete Empty Folders.bat %V


Hit OK and you can right away check in any folder if the shortcut is there by right clicking! 🙂

It works a bit differently if you're not the admin user in the computer, so I'll leave this link to some broader instructions on how to make this work.

✅ Annnnd... That's it! Now you have a cool tool to delete useless empty folders, along with a very cool method of adding shortcuts to your context menu - which I'm sure no one is going to abuse to the point of no return.

Rolando Barry