Solved What is the Robocopy syntax?


Haydon

Well-known member
Power User
VIP
Local time
11:32 AM
Posts
1,992
OS
Windows 10 Pro
What is the Robocopy syntax to do the following

Copy all contents of C:\Users\Me

to

a folder on an external drive D:\MeCopy
 

My Computer

System One

  • OS
    Windows 10 Pro
What is the Robocopy syntax to do the following

Copy all contents of C:\Users\Me

to

a folder on an external drive D:\MeCopy

It is easier to use a gui such as ChoEazyCopy. Whilst learning, it shows the command line syntax.


In you case, it would be

Code:
RoboCopy.exe  "C:\Users\Me" "D:\MeCopy" *.* /E /COPY:DAT /MT:8

1646781665768.png
 
Last edited:

My Computer

System One

  • OS
    Windows 10 Pro + others in VHDs
    Computer type
    Laptop
    Manufacturer/Model
    ASUS Vivobook 14
    CPU
    I7
    Motherboard
    Yep, Laptop has one.
    Memory
    16 GB
    Graphics Card(s)
    Integrated Intel Iris XE
    Sound Card
    Realtek built in
    Monitor(s) Displays
    N/A
    Screen Resolution
    1920x1080
    Hard Drives
    1 TB Optane NVME SSD, 1 TB NVME SSD
    PSU
    Yep, got one
    Case
    Yep, got one
    Cooling
    Stella Artois
    Keyboard
    Built in
    Mouse
    Bluetooth , wired
    Internet Speed
    72 Mb/s :-(
    Browser
    Edge mostly
    Antivirus
    Defender
    Other Info
    TPM 2.0
Image1.png
 

My Computers

System One System Two

  • OS
    Win 11 Home ♦♦♦22631.3374 ♦♦♦♦♦♦♦23H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Built by Ghot® [May 2020]
    CPU
    AMD Ryzen 7 3700X
    Motherboard
    Asus Pro WS X570-ACE (BIOS 4702)
    Memory
    G.Skill (F4-3200C14D-16GTZKW)
    Graphics Card(s)
    EVGA RTX 2070 (08G-P4-2171-KR)
    Sound Card
    Realtek ALC1220P / ALC S1220A
    Monitor(s) Displays
    Dell U3011 30"
    Screen Resolution
    2560 x 1600
    Hard Drives
    2x Samsung 860 EVO 500GB,
    WD 4TB Black FZBX - SATA III,
    WD 8TB Black FZBX - SATA III,
    DRW-24B1ST CD/DVD Burner
    PSU
    PC Power & Cooling 750W Quad EPS12V
    Case
    Cooler Master ATCS 840 Tower
    Cooling
    CM Hyper 212 EVO (push/pull)
    Keyboard
    Ducky DK9008 Shine II Blue LED
    Mouse
    Logitech Optical M-100
    Internet Speed
    300/300
    Browser
    Firefox (latest)
    Antivirus
    Bitdefender Internet Security
    Other Info
    Speakers: Klipsch Pro Media 2.1
  • Operating System
    Windows XP Pro 32bit w/SP3
    Computer type
    PC/Desktop
    Manufacturer/Model
    Built by Ghot® (not in use)
    CPU
    AMD Athlon 64 X2 5000+ (OC'd @ 3.2Ghz)
    Motherboard
    ASUS M2N32-SLI Deluxe Wireless Edition
    Memory
    TWIN2X2048-6400C4DHX (2 x 1GB, DDR2 800)
    Graphics card(s)
    EVGA 256-P2-N758-TR GeForce 8600GT SSC
    Sound Card
    Onboard
    Monitor(s) Displays
    ViewSonic G90FB Black 19" Professional (CRT)
    Screen Resolution
    up to 2048 x 1536
    Hard Drives
    WD 36GB 10,000rpm Raptor SATA
    Seagate 80GB 7200rpm SATA
    Lite-On LTR-52246S CD/RW
    Lite-On LH-18A1P CD/DVD Burner
    PSU
    PC Power & Cooling Silencer 750 Quad EPS12V
    Case
    Generic Beige case, 80mm fans
    Cooling
    ZALMAN 9500A 92mm CPU Cooler
    Mouse
    Logitech Optical M-BT96a
    Keyboard
    Logitech Classic Keybooard 200
    Internet Speed
    300/300
    Browser
    Firefox 3.x ??
    Antivirus
    Symantec (Norton)
    Other Info
    Still assembled, still runs. Haven't turned it on for 13 years?

My Computer

System One

  • OS
    Windows 10 Pro + others in VHDs
    Computer type
    Laptop
    Manufacturer/Model
    ASUS Vivobook 14
    CPU
    I7
    Motherboard
    Yep, Laptop has one.
    Memory
    16 GB
    Graphics Card(s)
    Integrated Intel Iris XE
    Sound Card
    Realtek built in
    Monitor(s) Displays
    N/A
    Screen Resolution
    1920x1080
    Hard Drives
    1 TB Optane NVME SSD, 1 TB NVME SSD
    PSU
    Yep, got one
    Case
    Yep, got one
    Cooling
    Stella Artois
    Keyboard
    Built in
    Mouse
    Bluetooth , wired
    Internet Speed
    72 Mb/s :-(
    Browser
    Edge mostly
    Antivirus
    Defender
    Other Info
    TPM 2.0
Darn stupid auto interpretation made
Code:
:D
into a smiley!

Fixed it by use Code tags


If desired, you can also use "Plain" tags to turn off the interpretation.
On TF you would use "NoParse" instead of "Plain"

Image1.png


RoboCopy.exe "C:\Users\Me" "D:\MeCopy" *.* /E /COPY:DAT /MT:8
 
Last edited:

My Computers

System One System Two

  • OS
    Win 11 Home ♦♦♦22631.3374 ♦♦♦♦♦♦♦23H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Built by Ghot® [May 2020]
    CPU
    AMD Ryzen 7 3700X
    Motherboard
    Asus Pro WS X570-ACE (BIOS 4702)
    Memory
    G.Skill (F4-3200C14D-16GTZKW)
    Graphics Card(s)
    EVGA RTX 2070 (08G-P4-2171-KR)
    Sound Card
    Realtek ALC1220P / ALC S1220A
    Monitor(s) Displays
    Dell U3011 30"
    Screen Resolution
    2560 x 1600
    Hard Drives
    2x Samsung 860 EVO 500GB,
    WD 4TB Black FZBX - SATA III,
    WD 8TB Black FZBX - SATA III,
    DRW-24B1ST CD/DVD Burner
    PSU
    PC Power & Cooling 750W Quad EPS12V
    Case
    Cooler Master ATCS 840 Tower
    Cooling
    CM Hyper 212 EVO (push/pull)
    Keyboard
    Ducky DK9008 Shine II Blue LED
    Mouse
    Logitech Optical M-100
    Internet Speed
    300/300
    Browser
    Firefox (latest)
    Antivirus
    Bitdefender Internet Security
    Other Info
    Speakers: Klipsch Pro Media 2.1
  • Operating System
    Windows XP Pro 32bit w/SP3
    Computer type
    PC/Desktop
    Manufacturer/Model
    Built by Ghot® (not in use)
    CPU
    AMD Athlon 64 X2 5000+ (OC'd @ 3.2Ghz)
    Motherboard
    ASUS M2N32-SLI Deluxe Wireless Edition
    Memory
    TWIN2X2048-6400C4DHX (2 x 1GB, DDR2 800)
    Graphics card(s)
    EVGA 256-P2-N758-TR GeForce 8600GT SSC
    Sound Card
    Onboard
    Monitor(s) Displays
    ViewSonic G90FB Black 19" Professional (CRT)
    Screen Resolution
    up to 2048 x 1536
    Hard Drives
    WD 36GB 10,000rpm Raptor SATA
    Seagate 80GB 7200rpm SATA
    Lite-On LTR-52246S CD/RW
    Lite-On LH-18A1P CD/DVD Burner
    PSU
    PC Power & Cooling Silencer 750 Quad EPS12V
    Case
    Generic Beige case, 80mm fans
    Cooling
    ZALMAN 9500A 92mm CPU Cooler
    Mouse
    Logitech Optical M-BT96a
    Keyboard
    Logitech Classic Keybooard 200
    Internet Speed
    300/300
    Browser
    Firefox 3.x ??
    Antivirus
    Symantec (Norton)
    Other Info
    Still assembled, still runs. Haven't turned it on for 13 years?
Thanks, guys, it gives me a start (y)(y)
 

My Computer

System One

  • OS
    Windows 10 Pro
I use robocopy "C:\folder1" "E:\externalfolder" /mir /e /dst
 

My Computers

System One System Two

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Beelink SEI8
    CPU
    Intel Core i5-8279u
    Motherboard
    AZW SEI
    Memory
    32GB DDR4 2666Mhz
    Graphics Card(s)
    Intel Iris Plus 655
    Sound Card
    Intel SST
    Monitor(s) Displays
    Asus ProArt PA278QV
    Screen Resolution
    2560x1440
    Hard Drives
    512GB NVMe
    PSU
    NA
    Case
    NA
    Cooling
    NA
    Keyboard
    NA
    Mouse
    NA
    Internet Speed
    500/50
    Browser
    Edge
    Antivirus
    Defender
    Other Info
    Mini PC used for testing Windows 11.
  • Operating System
    Windows 10 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom
    CPU
    Ryzen 9 5900x
    Motherboard
    Asus Rog Strix X570-E Gaming
    Memory
    64GB DDR4-3600
    Graphics card(s)
    EVGA GeForce 3080 FT3 Ultra
    Sound Card
    Onboard
    Monitor(s) Displays
    ASUS TUF Gaming VG27AQ. ASUS ProArt Display PA278QV 27” WQHD
    Screen Resolution
    2560x1440
    Hard Drives
    2TB WD SN850 PCI-E Gen 4 NVMe
    2TB Sandisk Ultra 2.5" SATA SSD
    PSU
    Seasonic Focus 850
    Case
    Fractal Meshify S2 in White
    Cooling
    Dark Rock Pro CPU cooler, 3 x 140mm case fans
    Mouse
    Logitech G9 Laser Mouse
    Keyboard
    Corsiar K65 RGB Lux
    Internet Speed
    500/50
    Browser
    Chrome
    Antivirus
    Defender.
What is the Robocopy syntax to do the following

Copy all contents of C:\Users\Me

to

a folder on an external drive D:\MeCopy

Is there a particular point that is confusing you?

RoboCopy syntax is shown in response to the command
Code:
RoboCopy /?

There is further guidance in
Robocopy - SS64
RoboCopy - MSDocs

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
Well, I am new to Robocopy and I have not really used CLI at all (grew up with GUI) I am taking this opportunity to dabble in both :):)

In my OP I wrote 'copy' but what I actually want is 'mirror'. I found the following code that probably does that, no?

MIRROR all contents of C:\Users\Me

to

a folder on an external drive D:\MeCopy
------------------------
Backup a Server:
The script below copies data from FileServ1 to FileServ2, the destination holds a full mirror along with file security info. When run regularly to synchronize the source and destination, robocopy will only copy those files that have changed (change in time stamp or size).

@ECHO OFF
SETLOCAL

SET _source=\\FileServ1\e$\users

SET _dest=\\FileServ2\e$\BackupUsers

SET _what=/COPYALL /B /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /MIR :: MIRror a directory tree

SET _options=/R:0 /W:0 /LOG:C:\batch\RoboLog.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging

ROBOCOPY %_source% %_dest% %_what% %_options%
 

My Computer

System One

  • OS
    Windows 10 Pro

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
Denis, can you please look at the script below? I am trying to emulate what File History does (mirroring the Users folder to a folder on an external drive) but don't laugh if I make cute mistakes :eek1:
--------------------------
@ECHO OFF
SETLOCAL

SET _source=\C:\Users\Me

SET _dest=\D:\MeCopy

SET _what=/COPYALL /B /MIR /S
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /MIR :: MIRror a directory tree
:: /S :: copy subfolders

SET _options=/R:0 /W:0 /LOG:C:\batch\RoboLog.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging

ROBOCOPY %_source% %_dest% %_what% %_options%
 

My Computer

System One

  • OS
    Windows 10 Pro
@ECHO OFF
I suggest you do not include that line until you have finished debugging your script.
It hides some responses so might hide something that would help you.
I run all my scripts minimised [by setting that in their shortcuts] so I don't care what is shown in the command window. For this reason, I never use echo off.


This is unnecessary. You are not using anything that would be affected by it.


SET _source=\C:\Users\Me

SET _dest=\D:\MeCopy
Both variables have a stray \ in front of their paths.
D:\MeCopy might well exist but \D:\MeCopy does not.

I do not know why you include a _ as the first character of every variable name. It does no harm but it also does not good.
It rings a faint bell from many moons ago.


If you read RoboCopy's built in Help or the links I gave you, you will see the defaults RoboCopy uses. I don't see that adding in /CopyAll adds anything useful. I don't recall ever using it myself.


Having no retries means it might fail when some retries might allow it to work. It's up to you.
I became very conscious of this when I added a very slow computer to my home network. It needed several goes a lot of the time.


/LOG:C:\batch\RoboLog.txt /NFL /NDL
Doesn't /log contradict /NFL /NDL?
I never use logs so am only going by their explanations in the Help file etc.


Try your script out on some rough & ready test folders. Just copy any old rubbish into them since you'll delete them afterwards.


Best of luck,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
Denis, is the following a good starting point? Also, what does the last line of the script do?
--------------------------
:: @ECHO OFF
:: Hide this line until script is fully debugged

:: SETLOCAL
:: This line may not affect anything

SET source=C:\Users\Me

SET dest=D:\MeCopy

SET what=/B /MIR /S
:: /COPYALL :: COPY ALL file info BUT superfluous
:: /B :: copy files in Backup mode
:: /MIR :: MIRror a directory tree
:: /S :: copy subfolders

SET options=/R:5 /W:0
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file BUT illogical in combination with the following switches AND I probably do not read the logs
:: /NFL :: No file logging
:: /NDL :: No dir logging

:: This robocopy script copies the contents of the Me users folder to the MeCopy folder on the external drive, the destination holds a full mirror along with file security info. Run this scipt regularly to synchronize the source and destination, robocopy will only copy those files that have changed (change in time stamp or size).

:: Unclear to me what the last line does
ROBOCOPY %source% %dest% %what% %options%
 
Last edited:

My Computer

System One

  • OS
    Windows 10 Pro
The last line actually carries out the RoboCopy operation.
- All your earlier lines were just setting it up.
- It does what you have written in the comments :: This robocopy script copies the contents of the Me users folder to the MeCopy folder …
- I was concerned about one word in those comments.
- - RoboCopy only operates one-way, it copies from Source to Destination.​
- - So the word synchronize is okay as long as you appreciate that it is only working one-way around. I think you do but just wanted to make sure.​
- - You'd need a proper synchronisation utility to achieve two-way syncing.​
- - I haven't used synchronisation utilities since MS's own one was found to skip files without reporting them all to the user. That was at least a decade ago. It was that that made me start using RoboCopy for backing up.​

When you test it, you could [if you wanted to] alter it slightly so you can see what it looks like by just adding /l to it
ROBOCOPY %_source% %_dest% %_what% %_options% /l
which makes it show what it will do without actually doing it.

After it is all tested you should read this
Set up my Tools folder ditty - TenForums
to help you decide where to store the batch file.

All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
:: Unclear to me what the last line does
ROBOCOPY %_source% %_dest% %_what% %_options%

I missed something essential. You have changed the names of your variables so you need to change their names in the last line as well.
ROBOCOPY %source% %dest% %what% %options%


Now I realise why you asked about what the last line does.

The %---% identify that you are referring to variables that you or Windows have set up.
Your SET source=C:\Users\Me line defines a variable called source and gives it the value C:\Users\Me
So in your last line
%source%
Windows retrieves its value
C:\Users\Me
then uses that in the command.

The same applies to the other variables in your last line %dest% %what% %options%
when the script reads the %-----% it knows you mean a variable so it gets its value to use in their place.

So your last line
ROBOCOPY %source% %dest% %what% %options%
means
ROBOCOPY C:\Users\Me D:\MeCopy /B /MIR /S /R:5 /W:0

You can always write out the values in full every time but variables can add a great deal of power to batch files

Windows creates some variables of its own that you can use but in many batch files it's the ones you set up yourself that you are most interested in. If you open a Command window [not a PowerShell window] and enter the command
Set
on its own without anything following then it will list all the variables that Windows has set up already. Mine, for example, includes the line USERNAME=denis
If, just for example, I was guiding you through doing something, I might suggest pasting this in the File explorer address bar
C:\Users\%UserName%\AppData\Roaming
so you could get straight to the folder I wanted to say something about. Windows would interpret %UserName% using the list I just got you to display so I could get you to the right folder without having to ask what your username was or giving you a long-winded and confusing explanation about how to get there.

I think you will now have lots of questions. I will answer them but I should also point out that if you are learning scripting from scratch your investment of time, effort & grey hair will be better rewarded by studying PowerShell, a well-structured scripting method that is entirely unlike the mish-mash of unstructured batch file commands that have evolved haphazardly over the last several decades.
- You can use almost all commands, such as RoboCopy, in PowerShell scripts but the way PowerShell refers to many things, including variables, is radically different.
- I've listed some PowerShell guides in my ditty Batch file and PowerShell guides [post #7] - ElevenForum

All the best,
Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
Denis, I am going with the following script, it will take me a while with my 2 thumbs, wish me luck, I will post again if I have more questions, thanks!
--------------------------
:: @ECHO OFF
:: Hide this line until script is fully debugged

:: SETLOCAL
:: This line may not affect anything

SET source=C:\Users\Me

SET dest=D:\MeCopy

SET what=/B /MIR /S
:: /COPYALL :: COPY ALL file info BUT superfluous
:: /B :: copy files in Backup mode
:: /MIR :: MIRror a directory tree
:: /S :: copy subfolders

SET options=/R:5 /W:0
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file BUT illogical in combination with the following switches AND I probably do not read the logs
:: /NFL :: No file logging
:: /NDL :: No dir logging

:: This robocopy script copies the contents of the Me users folder to the MeCopy folder on the external drive, the destination holds a full mirror along with file security info. Run this scipt regularly to update the destination, robocopy will only copy those files that have changed at the source (change in time stamp or size).

:: The last line below executes the full or incremental backups of what was setup in the above
ROBOCOPY %source% %dest% %what% %options%
 

My Computer

System One

  • OS
    Windows 10 Pro
OK. You should not have any problems.

Best of luck,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
My first experiments with RoboCopy were a success :cool:

I ran the RoboCopy script as a .bat file on the external destination medium to copy the Documents folder onto the external destination medium.

In the first run, RoboCopy created the destination folder on the destination medium and filled it with subfolders and files.

In subsequent runs, RoboCopy supported the addition of new files, the deletion of old files, and the modification of old files.

In other words, RoboCopy provides a true mirror, although the mirror has to be updated with the subsequent runs.

I am pleasantly surprised at how fast RoboCopy works, especially the subsequent runs. At one point, with only a small change in one of the subsequent runs, I almost re-ran it, because I thought it failed to run, but not, it did run, and it just flashes like lightning!

The Documents folder icon is duplicated on the external destination medium. The Documents folder name is also duplicated on the external destination medium, regardless of what name appears in the RoboCopy script. I always had to glance at the navigation pane of File Explorer to ascertain which data I was looking at, at the original or at the copy, LOL

I conducted the above first experiments on my W11 laptop, and I am confident enough to continue my experiments on my W10 main work computer :cool:

I will mark this thread 'Solved'. Thanks to all who responded (y) Special thanks to Denis for the help with the RoboCopy script (y)
 

My Computer

System One

  • OS
    Windows 10 Pro
While trying to copy the entire contents of the Users folder, I discovered that RoboCopy tries to copy the hidden folder AppData. That turns out to be a well known problem (RoboCopy just runs and runs and runs forever) and it appears that there is no good way in RoboCopy to exclude the AppData folder (or exclude any folder or any file, for that matter) So, like many others, I simply listed the folders that I do want to have copied, like in the following 'list' script

robocopy.exe C:\Users\Me\Documents D:\MeCopy\Documents /B /MIR /S /R:2 /W:20
robocopy.exe C:\Users\Me\Pictures D:\MeCopy\Pictures /B /MIR /S /R:2 /W:20

I also noticed that RoboCopy does not copy folders with a blank in their names, e.g. Saved Games

I am still testing the 'list' script, as you can see from the switch /W:20 to give me 20 seconds time to see what is going on when I babysit the process.

The 'list' script does seem to work, but use it at your risk!
 

My Computer

System One

  • OS
    Windows 10 Pro
I discovered that RoboCopy tries to copy the hidden folder AppData
If you look at my sample script, you'll see the switch /XA:SH
I use that to stop it copying hidden and system items.
You could also use the /XD switch [e.g. /XD F:\Whatever\DitchSoon] if you wanted to be more specific but I think /XA:SH is much better.
So, in your case, you can add /XA:SH to the variable you've called options.


I also noticed that RoboCopy does not copy folders with a blank in their names, e.g. Saved Games
That is easily dealt with. Amend your script to
ROBOCOPY "%source%" "%dest%" %what% %options%
You'll need the same approach to using many other commands in Windows. They think they have finished reading when they see a blank space in a folder-file path unless it is enclosed in quotation marks. It never does any harm to enclose them in quotation marks even if they do not contain spaces and you can also see examples of this in my sample script.



All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296

Latest Support Threads

Back
Top Bottom