I saw this nice cmd command on this SU answer that removes empty folders in a one liner. I thought this would be very useful to have as a right click context-menu option for folders.
So I went over to "Computer\HKEY_CLASSES_ROOT\Directory\Background\shell" on the registry and added a key with a name and another command key underneath that with default value set to cmd.exe /s /c "for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d"".
I see the contextmenu option when I right click a folder, and when I click on the menu option, no cmd window opens and Explorer.exe restarts. The command works fine when I manually execute it in cmd though.
Why does this command not work when hit from a folder right-click contextmenu while it does work on it's own? It especially doesn't make sense to me that Explorer.exe crashes as a result of this.
cmd /s /ctocmd /k. It still doesn't work and no CMD window pops up at all. I don't know how to check if the cmd process actually starts or not. – DFSFOT Jan 11 '21 at 15:45%dfunctions here. But in terms of context menu commands, the Shell is tries to expand its variables before passing the arguement to cmd.exe. If you test a simple context command,powershell -NoExit -Command "'%d' | echo", under bothDirectory\Background\ShellandDirectory\Shell, you'll see that the *Background* version errors out. Examing existingDirectory\Backgroundentries shows%Vcorrectly expands to the folder path. – Keith Miller Jan 11 '21 at 20:39%%dinstead of%dand it worked. Thanks! – DFSFOT Jan 13 '21 at 11:03