Reputation: 31
I am trying to add a new option to the context menu for folders in Windows. I have managed to add the option and specify its command as follows:
xcopy.exe "%0\*" "c:\Destination\" /EHY
This code is added to regedit.exe:
I have a folder in the c:
drive named Destination
. I am trying to copy the folder that I right clicked to the Destination
folder, without a command prompt window.
xcopy is running and copying the content of the folder and in the foreground. How can I:
Destination
named after the copied folder.Upvotes: 3
Views: 1171
Reputation: 2732
The command that satisfies the two issues listed is at the very end. First, some notes of explanation.
When you add a shell command to the Windows Registry, you have several variables available to you (such as %1
, %L
, and %V
). Now, you would like a new folder in Destination
named after the copied folder. Parameter extensions (such as %~n1
) can strip everything from the full path and give you the name of the directory leaf.
However, these are not available when using the shell command from the Windows Registry. The most straightforward way to get a plain directory name is to create a temporary batch script, run it, and delete the batch script afterwards.
The following will copy the selected directory as a sub-directory inside Destination
:
cmd.exe /c echo @echo off>"C:\Destination\_tempxcopy.bat" & echo xcopy "%%~1\*" "C:\Destination\%~n1" /ECIQHY ^>nul>>"C:\Destination\_tempxcopy.bat" & call "C:\Destination\_tempxcopy.bat" "%1" & del "C:\Destination\_tempxcopy.bat"
This next part requires the use of a third-party utility.
The previous command will open a command window and leave it open as long as copying is in progress. To hide that window, use the tiny utility RunHiddenConsole
The following will copy the selected directory and hide the command window while copying:
"C:\Destination\RunHiddenConsole.exe" cmd.exe /c echo @echo off>"C:\Destination\_tempxcopy.bat" & echo xcopy "%%~1\*" "C:\Destination\%~n1" /ECIQHY ^>nul>>"C:\Destination\_tempxcopy.bat" & "C:\Destination\RunHiddenConsole.exe" /w "C:\Destination\_tempxcopy.bat" "%1" & del "C:\Destination\_tempxcopy.bat"
This could certainly be made more flexible and efficient, but the above command at least demonstrates the technique for accomplishing the task.
Upvotes: 1