Add "Empty Folder" to the Context Menu

SwissxPiplup

Distinguished
Aug 6, 2015
33
0
18,540
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.
 
Solution
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...

gardenman

Splendid
Moderator
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:
empty1.gif
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.
 
Solution

SwissxPiplup

Distinguished
Aug 6, 2015
33
0
18,540


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.
 

Paul Randleman

Reputable
Jun 13, 2015
3
0
4,510
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.
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:
empty1.gif
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.



to get this to work I had to change it to

Code:
cmd.exe /c move \"%1\\*.* \".

since we are emptying a directory why not remove the empty directory

Code:
cmd.exe /c move \"%1\\*.*\" . && rd \"%1\"

and pesky cmd window flash.. not my taste, lets hide it with runhiddenconsole
Code:
rhc cmd.exe /c move \"%1\\*.*\" . && rd \"%1\"


Complete .reg code:
Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\MoveFilesUp]
@="Bring Up and Clean Up"

[HKEY_CLASSES_ROOT\Directory\shell\MoveFilesUp\Command]
@="rhc cmd.exe /c move \"%1\\*.*\" . && rd \"%1\""



For anyone who is curious:

Code Notes:
These are registry snippets, that is why the all inner quotes are escaped with '\'


This has similar function to the great 'suction.exe' program except with this, directories are ignored, and it isn't recursive.


I'm still working on this, ill update if I get more