Add "Empty Folder" to the Context Menu

SwissxPiplup

Reputable
Aug 6, 2015
14
0
4,520
1
Hi there,

I was wondering if there is a way to add an option to the context menu that would empty the highlighted folder(s) to the previous folder, for example: Pictures > Black > White | Right click White | Select "Empty Folder" | contents of White empties into Black; Any folders within white won't empty themselves, they'll just move with the files into black.

Perhaps this would be easier to achieve with a batch file instead though; but a context menu option would be far more convenient than opening the folder, cutting, and pasting everything; or dragging everything into a separate file explorer window.

Thank you.
 

gardenman

Admirable
Herald
Hi, I'm not so sure that I would called it "Empty Folder". That to me would mean to empty all files in the folder to the Recycle Bin, but it's your choice.

First, create a Restore Point and make a backup of your registry. Here's the instructions: https://support.microsoft.com/en-us/help/322756/how-to-back-up-and-restore-the-registry-in-windows

At a minimum, open Regedit, find this key:
HKEY_CLASSES_ROOT\Directory\
Right click on it and choose Export. Save it as Backup.reg to your desktop. If things go wrong, double click on the file to restore it, then reboot to be sure it's fully loaded.

First I went here and looked at the code at the bottom.
https://www.howtogeek.com/howto/windows/add-the-command-prompt-to-the-windows-explorer-right-click-menu/
The 4 quotation marks in that code are incorrect so don't use it. I fixed them when I created the below code.

Rather than opening a command prompt, you want to move the files. This can be done with the move command. It took me a few tries to get this right. First, you have to use double slashes when adding a single slash to the registry (most programmers have this knowledge). I was also moving the files to ".." which means move up 1 folder, but it was moving up two folders. I finally figured out that the current folder is where you want to move the files to (which is a single period). Don't worry if you don't understand any of that.

In notepad, copy and paste the following:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\EmptyF1]
@="Empty Folder"
[HKEY_CLASSES_ROOT\Directory\shell\EmptyF1\Command]
@="cmd.exe /c move %1\\*.* ."


Save it as EmptyFolder.reg and then double click on it and merge it into your registry. It should immediately work. You will see the command prompt flash as it runs but it's very quick and expected.

Result:
You can change the "Empty Folder" on the 3rd line to something else if you want. I'd personally use something like "Move Files Up 1 Level" but that's your choice.
 

SwissxPiplup

Reputable
Aug 6, 2015
14
0
4,520
1


I would call it "Recycle Contents" if it were going to do that. ;) But in that case one may as well recycle the whole folder and not just the contents.

It works perfectly! Thank you so much for going through all that effort, I really appreciate it.
 

ASK THE COMMUNITY