I have a simple batch file that works great when I run it in the root directory of E:
ROBOCOPY E: G: /MIR /XD $RECYCLE.BIN "System Volume Information" .tmp.drive /R:1 /W:1
PAUSE
But when I ran it from a subdir on E:, it behaved as if I'd rewritten the syntax to be ROBOCOPY E:\Dir G: /MIR (etc.) and erased the entirety of my backup on G:
What is it about Windows *.bat files that makes them act like this, and is there a way I can rewrite it so it will execute the code as written no matter where I run it?
Thanks for any helpful info!
Batch file question
Moderator: DosItHelp
Re: Batch file question
I'm not entirely sure what your expectation is.
In your second example the folder E:\Dir is backed up into the root of G: as you specified. /MIR implies /PURGE which deletes all directories that are not in the source. So what do you think should have happened instead?
Steffen
In your second example the folder E:\Dir is backed up into the root of G: as you specified. /MIR implies /PURGE which deletes all directories that are not in the source. So what do you think should have happened instead?
Steffen
Re: Batch file question
Your batchfile does what you tell it to do.
By using only the drive specifier and not specifying the directory on that drive you are saying use the current direcory on the sourcedrive and the current directory on the destination drive.
That is not what you intended but it is how it works.
Flexibility comes with responsibility.
You can prevent this from happening by being more explicit with the locations, use absolute paths instead of the implicit 'current directory'.
By using only the drive specifier and not specifying the directory on that drive you are saying use the current direcory on the sourcedrive and the current directory on the destination drive.
That is not what you intended but it is how it works.
Flexibility comes with responsibility.
You can prevent this from happening by being more explicit with the locations, use absolute paths instead of the implicit 'current directory'.
Code: Select all
ROBOCOPY E:\ G:\ /MIR /XD $RECYCLE.BIN "System Volume Information" .tmp.drive /R:1 /W:1
PAUSE