Add 'Delete empty folders' to Windows context menu

一个人想着一个人 提交于 2019-12-18 16:52:31

问题


I'd like to add to context menu this nice shell script that automatically deletes all empty folders and subfolders under the folder it is run from:

for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"

To add such an item to (directories) context menu I should run a file with reg extension having a content similar to

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Delete empty folders]

[HKEY_CLASSES_ROOT\Directory\shell\Delete empty folders\Command]
@=for /f "usebackq delims=" %%d in (`"dir %1 /ad/b/s | sort /R"`) do rd "%%d"

but this one does not work. How should it be fixed to properly run the one liner shell script?


回答1:


Thanks to Joey comment I was able to find the following solution.

Step 1: create a file with reg extension (like for example add_delete_empty_folders_to_context_menu.reg) and put the following lines inside it:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Delete empty folders]

[HKEY_CLASSES_ROOT\Directory\shell\Delete empty folders\Command]
@="cmd /c for /f \"usebackq delims=\" %%d in (`\"dir \"%1\" /ad/b/s | sort /R\"`) do rd \"%%d\""

Step 2: double click on your reg file and give all the needed confirmations.

Now you have a handy Delete empty folders command in your context menu, popping up when you right-click on a directory. This works for me on Windows 7 and Windows 10.

Avoid abuse of this functionality, some softwares need their empty folders to work properly.

Follow up

If you experience trouble (as Enora, see below) you can try to use the following line in the reg file, in place of the original one:

@="cmd.exe /K for /f \"usebackq delims=\" %%d in (`\"dir \"%V\" /ad/b/s | sort /R\"`) do rd \"%%~d\""

I actually don't know if this version is more robust, I just report here the solution found by Enora for her case.




回答2:


E ia ora na tatou

Here is another way:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\MenuDelZem]
"MUIVerb"="Supprimer les dossiers vides"
"Icon"="imageres.dll,-89"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\background\shell\MenuDelZem]
"MUIVerb"="Supprimer les dossiers vides"
"Icon"="imageres.dll,-89"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\open]
"MUIVerb"="Supprimez-les 🚯"
"Icon"="imageres.dll,-89"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\open\command]
@="cmd /c ROBOCOPY . .  /S /MOVE"


来源:https://stackoverflow.com/questions/34018590/add-delete-empty-folders-to-windows-context-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!