run robocopy bat to copy entire drive to another drive

cherrytree picture cherrytree · Apr 25, 2014 · Viewed 85.2k times · Source

I'm trying to run a simple backup (mirror) of one entire drive (d:) to another drive (k:). I've created a .bat file ('backup.bat') defining the source (d:) and destination (k:) and placed this batch file within a folder on the d drive (d:\temp). When I double-click on the batch file it defines the source as d:\temp, instead of what I've defined it as in the batch file; d:.

Here is the text in the .bat file:

@echo off
echo To begin backing up data:
pause
robocopy "D:" "K:" /L /v                 
echo.
pause
exit

And this is what shows up when I double-click on the backup.bat

enter image description here

As you can see, source is defined as d:\temp. This is where the batch file is located, but in the batch file I defined it as D:. For some reason, the destination is defined correctly.

Any ideas?

-al

EDIT: If I add the '/' to the source and destination location, see code below, I see even more odd behavior (see screenshot). The source is now both the defined source and destination combined, w/ no destination.

@echo off

echo To begin backing up data:
pause

robocopy "D:\" "K:\" /L /v


echo.            
pause
exit

enter image description here

And, if I remove the "" from the source and destination....IT WORKs!

@echo off

echo To begin backing up data:
pause

robocopy D:\ K:\ /L /v
echo.            
pause
exit

enter image description here

Answer

PA. picture PA. · Apr 25, 2014

with "D:" you are not specifying the root directory of the D drive (D:\) but the current directory of D instead, (D:\temp in your example).

To solve this problem, just add \ to the source spec (and while there, to the dest spec as well)

robocopy d:\ k:\ /L /v