Multi Commander > Support and Feedback
Issue with .bat and robocopy.
Mathias (Author):
If it works hardcoded it must be possible to make it work.
You just have to make sure that the generated line look exactly as the hardcoded. with quotes and trailing slashes in the same places.
So what does your hardcodes line look like exactly. and what does the generated line looks like (Not the line you write in the edit.. the finished line that MC generates)
what are the difference between them ?
ice-man:
This is getting crazy.. This should be simple to figure out.. If it works hardcode it then it should be possible to get it working
And it is working.. Took me 3 min to figure out... and all the information for getting it to run was already in this topic.
First doing a quick test you notice that RoboCopy do NOT like path to have a trailing slash ( \ at the end ) if the path is quoted.
BUT we do want to use quoted path since we do want to support spaces in the path. So we must make sure there is no \ at the end.
So what are ${sourcepath} and ${targetpath} returning ? Quick test show that they are returning a quoted path WITH trailing slash
( eg "R:\My Folder\" )
And since we know that robocopy do not like trailing slashes they need to be removed.
And that can be done using BAT scripting. and how to do that is shown in a previous post by mathias in the topic.
So instead of sending ${sourcepath} to the robocopy line we set it to a BAT script variable.
and then we do bat scripting to remove the quotes, then we remove the trailing slash, then readd quotes again
and now the "fix" path is in a BAT script valiable named SOURCE so then we use that for robocopy instead as %SOURCE%
--- Code: ---SET SOURCE=${sourcepath}
rem Remove Quotes
SET SOURCE=%SOURCE:"=%
rem Remove Trailing Slash
IF %SOURCE:~-1%==\ SET SOURCE=%SOURCE:~0,-1%
rem Add quotes again
SET SOURCE="%SOURCE%"
--- End code ---
and we do the same for ${targetpath}
A complete script will look like
--- Code: ---SET SOURCE=${sourcepath}
rem Remove Quotes, Remove Trailing slash, Readd Quotes
SET SOURCE=%SOURCE:"=%
IF %SOURCE:~-1%==\ SET SOURCE=%SOURCE:~0,-1%
SET SOURCE="%SOURCE%"
SET TARGET=${targetpath}
rem Remove Quotes, Remove Trailing slash, Readd Quotes
SET TARGET=%TARGET:"=%
IF %TARGET:~-1%==\ SET TARGET=%TARGET:~0,-1%
SET TARGET="%TARGET%"
robocopy %SOURCE% %TARGET% /TEE /MT /MIR /DCOPY:T /COPY:DAT /XD AppData /XJ /FFT /ZB /SEC /XA:SH /R:1 /W:1
pause
--- End code ---
And there is it..
Case closed.
nicedreams:
Haven't tried to mess with this in a bit and decided to come back to it. Thanks for the script that you wrote up for this.
I have tried it and still getting issues. Only spent a few minutes so far looking at the issue. Here it is below:
(This is using a copy and paste of your code you provided.)
================================================================
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Sunday, August 10, 2014 7:22:48 PM
Source : D:\testfolder\
Dest : D:\scans\
Files : *.*
Exc Dirs : AppData
Options : *.* /FFT /TEE /S /E /DCOPY:DAT /COPY:DATS /PURGE /MIR /ZB /XJ /XA:SH
/MT:8 /R:1 /W:1
------------------------------------------------------------------------------
ERROR : You do not have the Backup and Restore Files user rights.
***** You need these to perform Backup copies (/B or /ZB).
ERROR : Robocopy ran out of memory, exiting.
ERROR : Invalid Parameter #%d : "%s"
ERROR : Invalid Job File, Line #%d :"%s"
Started : %s %s
Source %c
Dest %c
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.
For more usage information run ROBOCOPY /?
**** /MIR can DELETE files as well as copy them !
Press any key to continue . . .
================================================================
nicedreams:
Tried messing with it and so I deleted the entire robocopy string and just put
robocopy %SOURCE% %TARGET% /MIR
It looked like it went right through, but now all my test files in my source and destination are gone and don't have a clue what happened. Using /MIR is just a mirror function so should have my data in source still. I do from command line.
Don't worry about this function anymore. I don't know if you are testing this on your own computer or just writing code and having me try it. Windows Vista/7/8 has robocopy built in and is awesome. I just used 2 directories and some test files to try this out. But if files just deleted from using robocopy within MultiCommander with the /MIR command then it's not enough for me to trust MC with Robocopy.
Mathias (Author):
Ice-Man's script works. I tried it..
Look at the error
--- Quote from: nicedreams on August 11, 2014, 04:26:34 ---"ERROR : You do not have the Backup and Restore Files user rights.
***** You need these to perform Backup copies (/B or /ZB).
ERROR : Robocopy ran out of memory, exiting.
--- End quote ---
You probably need to run the script as admin as robocopy need more then standard permissions. Also it says it run out of memory
The error texts are from robocopy.. not MC. MC ONLY creates a bat script from the script you wrote in MC. The only thing MC do are to replace MC specific tags like ${sourcepath}, And then the script is handed off to Windows just like all normal .bat script.
MC do not run the bat script it self. Windows run the script using cmd.exe as all bat script are.
And MC did not delete your files.. robocopy did. MC only creates the script. and then windows run that script
My guess it that you did /MIR but swapped the source and destination parameter in one of your tests.
using /MIR will delete files on target if that files does not exists on source.
If you are going to run bat script you need to understand how bat scripting work.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version