I have created a .reg with this to add a Delete empty folders
command in my context menu. When I right click on a folder, this should delete its empty child folders.
I have the "Delete empty folders" in my context menu but when I select this, a cmd windows open and I get this error: .. was unexpected at this time. Any idea why?
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\""
The code comes from @mmj (here)
Edit: thanks to JosephZ help here is the solution:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Delete empty folders]
[HKEY_CLASSES_ROOT\Directory\shell\Delete empty folders\Command]
@="cmd.exe /K for /f \"usebackq delims=\" %%d in (`\"dir \"%V\" /ad/b/s | sort /R\"`) do rd \"%%~d\""
The dir command resolves to
but should resolve to
Thus it should be
Update: If you have a batch working, why not call it from the context menu?
I don't apprehend why your code fails. For debugging purposes: both next
.reg
s work:Changes made on your code:
cmd.exe
instead ofcmd
;/K
switch to keep command prompt window open;%V
instead of%1
but work with%1
as well;@echo
instead ofrd
as I do not want to delete any directory even if empty (merely for debug);%%~d
instead of%%d
.Another escaping approach:
Excerpted from
cmd /?
:Edit: the solution (suggested by the OP Arone time after time):