By Ivy / Last update December 13, 2021

How to Sync Two Folders with Command Line?

How to sync two folders with Robocopy?

Hi, we have two shared folders. One is primary which is shared with the user and almost about to fill and the other is not shared yet but I want to sync all the data from primary to new one. How can I use robocopy to sync new folder with primary one so that I don't sync current files already in new folder and sync any changes that are being performed in primary folder to new folder while users are using the primary folder share. New folder will be the new share for all users eventually. Thanks.

- Question from social.technet.microsoft.com

Sometimes, you may need to sync two folders located in different computers or locations, to make the two folders keep the same content. Here we will show you different ways to perform Windows sync two folders with command line tool.

Robocopy Command Line

Robocopy as an one-way sync solution, provides you different parameters to sync two folders in Windows 11/10/8/7, let’s see how it works.

If you prefer to use Robocopy to sync two folders, please know the syntax of Robocopy:

robocopy [Source] [Destination] [(File)( ...)] [(Options)]

1. [Source] specifies the path to the source directory.

2. [Destination] specifies the path to the destination directory.

3. [(File)( ...)] specifies the file or files to be copied.

4. [(Options)] adds some copy options, such as:

  • /s: Copies subdirectories. Note that this option excludes empty directories.

  • /e: Copies subdirectories. Note that this option includes empty directories.

  • /lev: Copies only the top N levels of the source directory tree.

  • /z: Copies files in restartable mode.

  • /b: Copies files in Backup mode.

  • /zb: Uses restartable mode. If access is denied, this option uses Backup mode.

  • /efsraw: Copies all encrypted files in EFS RAW mode.

  • /copyall: Copies all file information, including D (Data), A (Attributes), T (Time stamps), S (Security: NTFS access control list (ACL)), O (Owner information), U (Auditing information)

To know more parameters you could use, please input robocopy /? to get more details.

Robocopy Commands

Robocopy Sync Two Folders (One-Way)

To sync two shared folders with Windows 11/10 command line tool - Robocopy, please follow the steps listed. 

1. Input the cmd in Windows 11/10 search box, and right click the Command Line, choose Run as administrator.

2. For example, sync tmp folder(and its subfolders) located in \\192.168.0.250\PublicShare\ to \\192.168.0.58\WorkD, please input the following command line:

robocopy \\192.168.0.250\PublicShare\temp \\192.168.0.58\WorkD /e /copy:DAT /mt /z

Robocopy Sync Two Folders 

  • /copy:DAT: means you will copy the source folder to destination folder with D (Data), A (Attributes), T (Time stamps), and you could modify these copied files. If you don’t want to modify these folders and files, you could replace /copy:DAT to /copyall or /copy:DATSOU.

  • /mt: Creates multi-threaded copies with 8 threads.

All the files will be synced from \\192.168.0.250\PublicShare\temp to \\192.168.0.58\WorkD.

Robocopy Incremental Sync

Windows sync two folders with command line tool - Robocopy is quite simple as long as you specify the right parameters. Besides, Robocopy could create incremental sync task for you.

If there is a change on the source folder, you could use /xo or /xc to let Robocopy sync changes only to the destination folder.

Such as, sync changed part from source \\192.168.0.250\PublicShare\temp to \\192.168.0.58\WorkD in restart mode and Creates multi-threaded copies with 8 threads, input the following command line:

robocopy \\192.168.0.250\PublicShare\temp \\192.168.0.58\WorkD /e /copy:DAT /mt /z /xc /xn /xo

Robocopy Incremental Sync

  • /xo: Excludes older files (excludes existing files older than the copy in the source directory). 

  • /xc: Excludes changed files (excludes existing files with the same timestamp, but different file sizes).

  • /xn: Excludes newer files (excludes existing files newer than the copy in the source directory).

  • With /xc, /xn, /xo specified, Robocopy will exclude files existing in the destination directory.

Robocopy Real Time Sync Two Folders

As a matter of fact, Robocopy offers you /mot:  to monitor changes in M minutes (only accept minutes as argument), you can’t monitor changes less than one minutes.

For example, monitor every one minutes based on the above command, type the command:

robocopy \\192.168.0.250\PublicShare\temp \\192.168.0.58\WorkD /e /copy:DAT /mt /z /xc /xn /xo /mot:1

Robocopy Real Time Sync Two Folders

  • /mot:: Monitors the changes in source every N minutes and sync it to destination.

Or you could use batch files to add sync task to Windows Task Scheduler to continuously copy all files changes.

Besides, if you want to perform mirror sync with Robocopy, you could specify the /purge parameter to delete destination files and directories that no longer exist in the source. 

Windows Sync Two Folders via Command Line (Robocopy) Limitation

However, there are some restrictions using Robocopy sync two folders:

  • It’s quite complicated to understand all the parameters if you are not familiar with the command line tool - Robocopy.

  • You will lose important files and folders once specified wrong parameters.

  • Robocopy sync folders both ways (two way sync) is not supported.

Easier Way to Sync Two Folders in Windows 11/10/8/7

If you want to sync files more flexible and easily, it’s highly recommended to try the best file synchronization software - AOMEI Backupper Professional, which is designed for Windows XP, Vista, 7, 8, 8.1,10 and 11, including 32-bit and 64-bit. You could sync two folders easier on the intuitive GUI.

With the help of AOMEI Backupper Professional, you could:

  • Sync folders to multiple destinations: you could sync files and folders to local disk, external hard drive (HDD or SSD), CD/DVD, USB flash drive, network share or NAS, even to the cloud(Google Drive, Dropbox, OneDrive, Box, etc.).

  • Flexible sync features: It offers you basic sync, mirror sync, real time sync, and the two way sync.

  • User-friendly interface: It's easy to operate even you're the novice.

Please download the file synchronization software for Windows - AOMEI Backupper Professional 30 day free trial to have a try:

Download Free Trial Win 11/10/8.1/8/7/XP
Secure Download

To show you how it works to sync two folders in real time in Windows 11/10, please refer to the following instructions:

Step 1. launch AOMEI Backupper Professional on your Windows 10 computer, select Sync tab and then Real-Time Sync.

Real Time Folder Sync

Step 2. Press + Add Folder button > Share/NAS > Add Share or NAS Devices > input the Display Name and Network Path to add the network share, and choose the folder you want to sync.

Add Shared Folder

Add Network Path

Step 3. Click the triangle icon and tap Select a network location, and click Add Share or NAS Devices > input the Display Name and Network Path to add another destination network share, choose the folder as target.

Choose Shared Folder As Destination

Add Network Path

Step 4. Hit Start Sync >> to sync two folders in real time in Windows 11/10.

Start Sync Shared Folder To Another Shared Folder

★Tip: the Options allows you comment the real time folder sync task, and verify the integrity of the files in the destination location during synchronization, etc.

After the first full folder sync, then any changes made on the source folder will be synced to the destination immediately.

Besides, you could set up a mirror sync with schedule, such as daily, weekly, monthly, event triggers, USB plug in. You will get the email or SMS notification after setting up email notification.

The Epilogue

Compared with Windows sync two folders via command line tool - Robocopy, the best file sync software - AOMEI Backupper Professional provides you flexible ways to sync two folders in Windows 11, 10, 8, 7.

If you are running Windows Server 2003, 2008, 2012, 2016, 2019 (including R2) and SBS 2003, 2008, 2011, please try AOMEI Backupper Server to enjoy.