Robocopy backing up with a batch file, but not to the same drive?

42 views Asked by At

I use this sort of command line in the batch files to backup data from my laptop to various external USB drives and also from one USB drive to another, using Robocopy:

Robocopy \ "D:\2TB Blue" /MIR /R:1 /W:1 /TEE /FFT /A-:SH

But, if I run that batch file on the same drive, e.g. D:, it'll dump a copy of D:\ to D:\2TB Blue, which is no use whatsoever.

Can anyone advise how to not run the batch file if the 'source' and 'destination' are on the same drive?

2

There are 2 answers

0
Trevit On

The Following Morning

So, I slept on it and worked it out:

If %CD:~0,2%==E: Goto Doh!

Robocopy \ "E:\2TB Blue" /MIR /R:1 /W:1 /TEE /FFT /A-:SH
Goto End

:Doh!
@Echo The Source and Destination are on the SAME drive!
pause

:End
2
Trevit On

ALSO, I have found out that Windows 11 has it's own way of dealing with batch files, that is completely at odds with what Windows 10 used to do.

On MY laptop using MY Windows account that has Administrator rights, if I create a batch file on D:\ containing just the following:

Dir
Pause

When I just double-click it, I'll see the list of files in whatever D: directory the .bat file's in. BUT, if I right-click and use "Run as administrator", it sods off to "C:\Windows\System32" and gives me that directory listing.

BUT if I add "CD /d %~dp0" in before the Dir, it forces the .bat file to run from the directory it's located in, whether it's a double-click, or a 'Run as administrator'.

WTF is that about Microsoft :-(