cmd - error "\.. was unexpected at this time" -


i have created .reg add delete empty folders command in context menu. when right click on folder, should delete empty child folders.

i have "delete empty folders" in context menu when select this, cmd windows open , error: .. unexpected @ time. 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 /f \"usebackq delims=\" %%d in (`\"dir \"%1\" /ad/b/s | sort /r\"`) rd \"%%d\"" 

the code comes @mmj (here)

edit: josephz here 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 /f \"usebackq delims=\" %%d in (`\"dir \"%v\" /ad/b/s | sort /r\"`) rd \"%%~d\"" 

i don't apprehend why code fails. debugging purposes: both next .regs work:

windows registry editor version 5.00  [hkey_classes_root\directory\shell\list subfolders2]  [hkey_classes_root\directory\shell\list subfolders2\command] @="cmd.exe /k /f \"usebackq delims=\" %%d in (`\"dir \"%v\" /ad/b/s | sort /r\"`) @echo \"%%~d\"" 

changes made on code:

  • cmd.exe instead of cmd;
  • /k switch keep command prompt window open;
  • %v instead of %1 work %1 well;
  • @echo instead of rd not want delete directory if empty (merely debug);
  • %%~d instead of %%d.

another escaping approach:

windows registry editor version 5.00  [hkey_classes_root\directory\shell\list subfolders]  [hkey_classes_root\directory\shell\list subfolders\command] @="cmd.exe /s /k \"for /f \"delims=\" %%d in ('dir \"%v\" /ad/b/s ^| sort /r') @echo \"%%~d\"\"" 

excerpted cmd /?:

if /c or /k specified, remainder of command line after switch processed command line, following logic used process quote (") characters:

  1. if of following conditions met, quote character on command line preserved:

    • no /s switch
    • exactly 2 quote characters
    • no special characters between 2 quote characters, special 1 of: &<>()@^|
    • there 1 or more whitespace characters between 2 quote characters
    • the string between 2 quote characters name of executable file.
  2. otherwise, old behavior see if first character quote character , if so, strip leading character , remove last quote character on command line, preserving text after last quote character.

edit: solution (suggested op arone time after time):

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 /f \"usebackq delims=\" %%d in (`\"dir \"%v\" /ad/b/s | sort /r\"`) rd \"%%~d\"" 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -