I often need to quickly copy the name of a folder in Windows 7, and so am trying to create an equivalent to the Copy as path item that appears in Extended context menus (i.e. when doing Shift+Right Click) that will copy only the name of the selected folder to the clipboard.
I've created the Registry key at:
HKEY_CLASSES_ROOT\Directory\shell\Copy folder name\command
...where all of my similar context-menu additions for folders are, and it can be seen here:
However, I've so far been unable to get the code that needs to be executed by the key working as it should. I've come across this solution to grab the current folder of a directory, and this one to pipe the directory name to the clipboard, and put them together to get the following:
for %* in (.) do set FolderName=%~nx* && echo %FolderName%| clip
This code works exactly as expected in the command line.
Prepending cmd /c to it, which is necessary to run a CMD instance from the Registry, gives the following:
cmd /c for %* in (.) do set FolderName=%~nx* && echo %FolderName%| clip
However, placing this in the value data of the Default string value in the \Copy folder name\command key, and then right-clicking a folder and clicking on Copy folder name fails to work.
Wrapping it in quotes also does nothing:
cmd /c "for %* in (.) do set FolderName=%~nx* && echo %FolderName%| clip"
What am I missing here?


cmd /V:ON /c "for %* in (.) do set FolderName=%~nx* && echo !FolderName!|clip"– Vomit IT - Chunky Mess Style Apr 10 '18 at 23:28"C:\\folderToClip.bat \"%1\"– HackSlash Apr 10 '18 at 23:31/kinstead of/cin the hope that the command window would remain open for debugging purposes, and ditto forpause- no such luck. – Hashim Aziz Apr 10 '18 at 23:38"FolderName=%~nx*"quoting the variable that way too... i.e.cmd /V:ON /c "for %* in (.) do set "FolderName=%~nx*" && echo !FolderName!|clip"? I noticed this way trims off the trailing white space too. – Vomit IT - Chunky Mess Style Apr 10 '18 at 23:44