-1

I am trying to make a little shortcut for my daily work. I often have to copy some files from let's say C:\folder0\folder1\aaaa\ to C:\folder0\folder1\bbbb\.

I want to create a batch file shortcut in the send-to menu. So I would first select the files and then click on the new added shortcut to the batch file which should do the rest.

@echo off

:here
if '%1'=='' goto exit
"C:\Program Files (x86)\Notepad++\notepad++.exe" "%1"
echo %cd%
shift
goto here

:exit

I started with opening the files in Notepad++ and displaying the path. But I need a function that stores the path from the given files and changes the folder a to folder b. Afterwards it would take the new path for the standard copy function.

xcopy /s C:\source D:\target

I hope I could properly explain what I try to achieve.

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • The proper way to test if a parameter is empty is [this](https://stackoverflow.com/a/2541820). Also, do you want to drag files into a batch file, and the batch file will open them with `Notepad++`? – double-beep Dec 28 '18 at 12:13
  • Possible duplicate of [Running a batch script by right clicking any file](https://stackoverflow.com/questions/6852833/running-a-batch-script-by-right-clicking-any-file) –  Dec 28 '18 at 12:28
  • I believe this should help you https://www.itprotoday.com/windows-8/how-do-i-pass-parameters-batch-file – montonero Dec 28 '18 at 12:39
  • See [Copying selected files from dated folder using batch file](https://stackoverflow.com/a/51337539/3074564). – Mofi Dec 28 '18 at 12:46
  • I see absolutely no reason to create a batch file or script for the task you've outlined. The very most you'd need is to add `C:\folder0\folder1\bbbb` as a new item in the `Send to` menu. I also would suggest that this is unnecessary too as all you'd need to do is to select one or more items in the Explorer window then use the context menu to 'Copy to' whichever location you require. You could also utilise two windows/tabs, _(depending upon your file manager of choice)_, and drag/drop, _(or key sequence)_, to copy between two known constant locations. – Compo Dec 29 '18 at 14:06

1 Answers1

-1

I found a solution. This is my code and it is working for me now as long as there are no spaces in the path (has someone an idea to fix that?)

@echo off
:here
if '%1'=='' goto exit
set strpath=%cd%
set strresult=%strpath:folder1=folder2%
@echo The original file '%1'
@echo New path %strresult%
coyp /b/v/y "%1" "%strresult%"
shift
goto here
:exit
pause
  • Change `coyp` to `copy`. If the path comes to you quoted, use `"%~1"`. – lit Dec 28 '18 at 14:47
  • Replace `if '%1'=='' goto exit` by `if "%~1" == "" goto exit` to get this line also working with first argument string containing space or one of these characters ``&()[]{}^=;!'+,`~`` as explained by help of Windows command processor in last paragraph on last help page output on running in a command prompt window `cmd /?`. Well `goto exit` could be replaced also by `goto :EOF` or `exit /B` or `exit`. See [Where does GOTO :EOF return to?](https://stackoverflow.com/a/37518000/3074564) __EXIT__ is an internal command of `cmd.exe` and therefore `exit` as label is possible, but not advisable. – Mofi Dec 29 '18 at 17:21
  • `coyp /b/v/y "%1" "%strresult%"` should be `copy /b /v /y "%~1" "%strresult%"` to really work. Run `copy /?` and `call /?` for help on command __COPY__ and an explanation of `%~1` in comparison to `%1`. And I recommend reading also [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) and use `set "strpath=%cd%"` and `set "strresult=%strpath:folder1=folder2%"` to get the code also working for a path containing `&` (ampersand). – Mofi Dec 29 '18 at 17:27