Windows context menu hides xcopy

I am trying to add a new option to the context menu for folders on Windows. I was able to add a parameter and specify its command like this:

xcopy.exe "%0\*" "c:\Destination\" /EHY

      

This code is added to the regedit.exe file

Snapshot here.

I have a folder in disk c:

named Destination

. I am trying to copy the folder I right clicked to a folder Destination

without a command prompt window.

What's going on: xcopy is running and copying content in the folder and foreground. Please help me with these two problems:

  • Run the xcopy command without showing the window.
  • Copy the folder to the new folder Destination

    named after the copied folder.

Thank.

+3


source to share


1 answer


The command that satisfies the above two problems is at the very end. First, some clarification.

When you add a shell command to the Windows registry, you have several variables available to you (for example %1

, %L

and %V

). Now you need a new folder in the Destination

named after the copied folder. Parameter extensions (for example %~n1

) can remove everything from the full path and give you the name of the catalog sheet. However, they are not available when using a shell command from the Windows registry. The easiest way to get the simple name of a directory is to create a temporary batch version of the script, run it and remove the script batch afterwards.

Next, the selected directory will be copied as a subdirectory 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 while copying is in progress. To hide this window, use the tiny RunHiddenConsole utility

Next, the selected directory will be copied and hide the command window when 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"

      

It can be made more flexible and efficient, but the above command at least demonstrates the technique for completing the task.

0


source







All Articles