Solved Question on RoboCopy Syntax


Haydon

Well-known member
Power User
VIP
Local time
6:50 PM
Posts
1,992
OS
Windows 10 Pro
I use in my RoboCopy script the switch

/XD C:\Users\name\AppData

to exclude the AppData directory at the source.

I'd like to exclude the following source directories

/XD C:\Users\name\.ms-ad
/XD C:\Users\name\3D Objects

but the syntax is now wrong because of the hyphen and the space. I seem to remember that it can be corrected with a small modification, but I forgot how. Sorry for the ignorant question, I am not a programmer.
 

My Computer

System One

  • OS
    Windows 10 Pro
I use in my RoboCopy script the switch

/XD C:\Users\name\AppData

to exclude the AppData directory at the source.

I'd like to exclude the following source directories

/XD C:\Users\name\.ms-ad
/XD C:\Users\name\3D Objects

but the syntax is now wrong because of the hyphen and the space. I seem to remember that it can be corrected with a small modification, but I forgot how. Sorry for the ignorant question, I am not a programmer.
Put the path name in quotes? /XD "C:\Users\name\3D Objects"
 

My Computer

System One

  • OS
    Windows 11 Pro 23H2 (RP channel)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Gigabyte
    CPU
    AMD Ryzen 5900X 12-core
    Motherboard
    X570 Aorus Xtreme
    Memory
    64GB Corsair Platinum RGB 3600MHz CL16
    Graphics Card(s)
    MSI Suprim X 3080 Ti
    Sound Card
    Soundblaster AE-5 Plus
    Monitor(s) Displays
    ASUS TUF Gaming VG289Q
    Screen Resolution
    3840x2160
    Hard Drives
    Samsung 990 Pro 2TB
    Samsung 980 Pro 2TB
    Samsung 970 Evo Plus 1TB
    Samsung 870 Evo 4TB
    Samsung T7 Touch 1TB
    PSU
    Asus ROG Strix 1000W
    Case
    Corsair D750 Airflow
    Cooling
    Noctua NH-D15S
    Keyboard
    Asus ROG Flare
    Mouse
    Logitech G903 with PowerPlay charger
    Internet Speed
    500Mb/sec
    Browser
    Microsoft Edge
    Antivirus
    Windows Defender
Ah yes, of course, and I can put several path names after the /XD switch, thanks!
 

My Computer

System One

  • OS
    Windows 10 Pro
Folks, RoboCopy experts,

I reviewed my year old RoboCopy script to copy my user files. The old script works well, but it had multi lines, each line specifying a copy operation. The new script below has essentially a single line to copy my user folder with exclusions of what I don't want to copy. It produces a copy of the exact same GBs although the new script has been structured a bit differently (not just syntax, but also substance)

Please review, I have prepended a Glossary to make my intentions clear and to make a review easy.

Thanks!

:: Glossary for the RoboCopy script at the end of this post
::
:: ROBOCOPY.EXE reference at robocopy
::
:: C:\Users\name = source = the entire user folder
::
:: D:\RCname = destination folder on an external backup medium, this destination folder will be created if none exists before
::
:: Now come the exclusions, the specified exclusions will not be copied
::
:: /XD "C:\Users\name\AppData" "C:\Users\name\.ms-ad" "C:\Users\name\3D Objects" This switch excludes from the source user folder the AppData folder, the .ms-ad folder, the 3D Objects folder. Note the quotation marks "..." whether they are required or not for syntax reasons
::
:: /XA:HST This switch excludes from the source user folder Hidden files, System files, Temporary files, i.e. files that are not strictly user files will not be copied
::
:: /XJ This switch excludes junction points, it covers /XJD and XJF for directories and files respectively, so that the latter switches do not have to be specified
::
:: Now come the copy options
::
:: /MIR This switch specifies a mirror of the source at the destination, the new directory tree at the destination folder will make additions, deletions and changes to an existing directory tree at the destination folder. If no directory tree exists at the destination folder, a new directory tree will be created.
::
:: /R:2 /W:0 These switches specify the number of retries and the wait time between retries in seconds
::
:: /MT:6 This switch enables multi-threaded copying with a default value of 8, but my old computer has a maximum of 8 threads, so I throttle it down to 6
::
:: Now come the logging options
::
:: /LOG:"D:\ERCLOG.txt" This switch will create a new log file at the external backup medium if none exists before, a new run will overwrite an existing log file.
::
:: /FP /BYTES /NS /NC /NFL /NDL These switches format the contents of the log file
::
:: pause Add this line to keep the command line window open
::
:: Trara, now comes the script!
ROBOCOPY.EXE C:\Users\name D:\RCname /XD "C:\Users\name\AppData" "C:\Users\name\.ms-ad" "C:\Users\name\3D Objects" /XA:HST /XJ /MIR /R:2 /W:0 /MT:6 /LOG:"D:\ERCLOG.txt" /FP /BYTES /NS /NC /NFL /NDL
pause
 
Last edited:

My Computer

System One

  • OS
    Windows 10 Pro
Looks good. Did you try it?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Yes, I did try it out, several times even, and I even tried out previous revisions as I progressed from one revision to the next.

As I wrote in the above, the year-old script and the newest revised script produce copies that are of the exact same size, exact means exact to 3 digits of GBs (they can't be mathematically exact because of the different dates)

If someone else wants to try it out:

> Copy the 2-line script (at the end of my previous post #4) in a Notepad file, edit as appropriate, and save as a TryOut.bat file
> Right click the TryOut.bat file and run as administrator
> Report back, including anything interesting in the ERCLOG.txt file

Note that it can take a long time to make the backup if your users folder is very large.
 

My Computer

System One

  • OS
    Windows 10 Pro
Back
Top Bottom