Batch file question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
drewdavis
Posts: 1
Joined: 23 Aug 2024 21:17

Batch file question

#1 Post by drewdavis » 23 Aug 2024 22:09

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file question

#2 Post by aGerman » 24 Aug 2024 05:41

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

OJBakker
Expert
Posts: 90
Joined: 12 Aug 2011 13:57

Re: Batch file question

#3 Post by OJBakker » 25 Aug 2024 12:19

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'.

Code: Select all

ROBOCOPY E:\ G:\ /MIR /XD $RECYCLE.BIN "System Volume Information" .tmp.drive /R:1 /W:1
PAUSE

Post Reply