IT ENGLISH BOARD

Robocopy command syntax and examples

Software
Author
author
Date
2019-08-30 19:17
Views
3745

Robocopy command syntax and examples





Robocopy command is used on Windows to copy files and directories from one location to another. This CMD command also prints a detailed report of the copy operation. Below you can find examples for using Robocopy in various usecases.

Copy a directory

Example: Copy all the files in the directory D:\dir1\data to E:\backup\data. Don’t include sub directories or the files stored in those.
Robocopy  D:\dir1\data E:\backup\data
The above command copies system files and hidden files too. Copy and Xcopy commands skip these files by default.
At the end of the command execution, it would print the summary like below.
          Total    Copied   Skipped  Mismatch    FAILED    Extras
Dirs : 22 22 0 0 0 0
Files : 113 113 0 0 0 0
Bytes : 42.96 m 42.96 m 0 0 0 0
Times : 0:00:01 0:00:00 0:00:00 0:00:00

Speed : 83744483 Bytes/sec.
Speed : 4791.897 MegaBytes/min.
Ended : Wed Oct 22 22:26:14 2014

Copy directory structure

Run the below Robocopy command to copy directory structure i.e deep copy of folder hierarchy and the data in all the subfolders.

Robocopy /S D:\dir1\data E:\backup\data
This command does not copy empty directories. To copy them, you need to add /E switch.
Robocopy /S /E  D:\dir1\data E:\backup\data

Delete files and directories from the source after copying

You can add /MOV switch to delete files and /MOVE switch to delete both files and directories.

For deleting files:
Robocopy /MOV /S /E  D:\dir1\data E:\backup\data
For deleting files and directories:
Robocopy /MOVE /S /E  D:\dir1\data E:\backup\data

Modify file attributes for the copied files

Using robocopy command we can also change attributes(system, hidden, readonly) of the copied files. This affects the attributes of the files in the new location, it does not impact the files in the source directory.

For example to copy all files from one directory to another directory and also set hidden attribute for all the files you can trigger ‘Robocopy’ with the below syntax.
Robocopy /S /E  /A+:H D:\dir1\data E:\backup\data

Mirror copy a directory

Below Robocopy command creates a replica of the source folder in the specified destination folder
Robocopy /MIR sourceFolder  destinationFolder
This command also deletes any extra files that are present in the destination and are not present in source.

Replicate access permission on destination folder

The option ‘/sec’ copies all the file access permissions to the destination folder also.
 robocopy /sec sourceFolder destinationFolder
Note that Robocopy copies the security ACLs also to the destination only if the file has been modified. If the file has not been modified, the ACLs won’t be applied on the destination. You can check this Microsoft’s post robocopy file permissions for deeper understanding.

Total Reply 0

Total 104
Number Title Author Date Votes Views
43
Robocopy command syntax and examples
author | 2019.08.30 | Votes 0 | Views 3745
author 2019.08.30 0 3745
42
Where are Windows 7 activation file stored?
author | 2019.08.28 | Votes 0 | Views 7010
author 2019.08.28 0 7010
41
Windows 7 Fix 0.0.0.0 Default Gateway Issue
author | 2019.08.16 | Votes 1 | Views 3438
author 2019.08.16 1 3438
40
How do I stop Chrome opening automatically on startup (Windows 10)? (5)
author | 2019.08.04 | Votes 0 | Views 3157
author 2019.08.04 0 3157
39
Q: What does it mean when the charger light is red instead of green (1)
author | 2019.08.02 | Votes 0 | Views 2838
author 2019.08.02 0 2838
38
your "default" contact/calendar data is stored in the default data file for the profile
author | 2019.07.24 | Votes 0 | Views 2600
author 2019.07.24 0 2600
37
How do I export contacts stored in the DYMO Label Software Address Book? (1)
author | 2019.07.24 | Votes 0 | Views 4225
author 2019.07.24 0 4225
36
How to Import Label Files for Dymo Printers
author | 2019.07.24 | Votes 0 | Views 2764
author 2019.07.24 0 2764
35
Moving Your DYMO Files to Another Computer
author | 2019.07.24 | Votes 0 | Views 3158
author 2019.07.24 0 3158
34
Why did I get Paypal API error code 11601?
author | 2019.07.13 | Votes 0 | Views 3449
author 2019.07.13 0 3449
New