Solved Question on RoboCopy Syntax


Haydon

Well-known member
Power User
VIP
Local time
2:08 PM
Posts
1,990
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 My Computer

At a glance

Windows 10 Pro
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 My Computer

At a glance

Windows 11 Pro 25H2 (RP channel)AMD Ryzen 7 9800X3D 8-core64GB Corsair Titanium 6000/CL30MSI Suprim 5080 SOC
OS
Windows 11 Pro 25H2 (RP channel)
Computer type
PC/Desktop
Manufacturer/Model
MSI
CPU
AMD Ryzen 7 9800X3D 8-core
Motherboard
MEG X870E Godlike
Memory
64GB Corsair Titanium 6000/CL30
Graphics Card(s)
MSI Suprim 5080 SOC
Sound Card
Soundblaster AE-9
Monitor(s) Displays
ASUS TUF Gaming VG289Q
Screen Resolution
3840x2160
Hard Drives
Samsung 9100 Pro 4TB (gen 5 x4, system drive/games)
Samsung 990 Pro 2TB
Samsung 980 Pro 2TB
Samsung 870 Evo 4TB
Samsung 870 Evo 2TB
Samsung T9 4TB
PSU
Seasonic PX-2200
Case
Bequiet! Dark Base Pro 901
Cooling
Noctua NH-D15S Chromax black
Keyboard
Logitech G915 X (wired)
Mouse
Logitech G903 with PowerPlay charger
Internet Speed
900Mb/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 My Computer

At a glance

Windows 10 Pro
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 My Computer

At a glance

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

My Computer My Computer

At a glance

Windows 11
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 My Computer

At a glance

Windows 10 Pro
OS
Windows 10 Pro

Latest Support Threads

Back
Top Bottom