You will learn more about Robocopy and examples to perform Windows sync two folders via command line - Robocopy. Meanwhile, this article offers an easier way.
"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 with Robocopy command line.
The problem is how do I sync two folders with Robocopy? I don't want to sync current files already in the new folder, only changes in the primary folder to new folder. Thanks."
Sometimes, you may need to sync two folders located in different computers or other locations, such as, internal or external drives, 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 one-way sync two folders More...>>
An easier way to sync two folders in Windows-AOMEI Backupper More...>>
Robocopy is a robust file copy command for Windows PCs and it allows you to copy files, directories, and even drives from one location to another. It provides you with different parameters to sync two folders in Windows 11/10/8/7.
๐ Robocopy command line syntax: You can specify the path to source and destination directory, files or folders you want to sync and other options.
robocopy [Source] [Destination] [(File)( ...)] [(Options)]
Source | It specifies path to source directory, type as, drive:\path or \\server\share\path. |
Destination | It specifies path to destination directory, type as, drive:\path or \\server\share\path. |
File | It specifies files you want to copy, type as, names/wildcards: default is "*.*". |
Options | It specifies copy, file, retrt, logging, and job options to use with robocopy command. |
๐ Common used options in Robocopy:
/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.
In general, Robocopy is a one way file sync solution, and you can sync files easily from one location to another as long as you use the right options. And I will introduce you to the most common cases below. Note that you need to run cmd as administrator in all the following situations.
The first case is to sync two folders on different computer through shared folder. For example, to 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
Notes:
/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.
Except for simply sync two shared folers, you still can create incremental sync task with Robocopy command line. You will use the /xo or /xc option, which has the ability to let Robocopy sync changes only to the destination folder.
For example, to 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
Notes:
/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).
/mt: Enable multithreaded copying and the default threads is 8. If you don't want to use the default, you can specify it yourself.
With /xc, /xn, /xo specified, Robocopy will exclude files existing in the destination directory.
Besides, Robocopy still offers you /mot: to monitor changes in M minutes (only accept minutes as argument). Note the changes less than one minutes will not be included.
For example, monitor every one minutes based on the above command, type the following command:
robocopy \\192.168.0.250\PublicShare\temp \\192.168.0.58\WorkD /e /copy:DAT /mt /z /xc /xn /xo /mot:1
Note:
/mot:: Monitors the changes in source every N minutes and sync it to destination.
Except for the above cases, you still can use batch files and Windows Task Scheduler to continuously copy all file changes.
Besides, you could specify the mirror sync task with the /purge parameter, it will delete destination files and directories that no longer exist in the source.
For two-way sync, you need to create a batch file with Notepad. For detailed steps, please refer to Robocopy two-way sync.
Robocopy is good assistant to helps you perform one way, but there are some restrictions using Robocopy sync two folders:
Robocopy parameters are quite complicated for computer novices to understand.
Robocopy does not copy open files.
Robocopy does not mirror files properly in system older than Windows Vista.
You will lose important files and folders once specified the wrong parameters.
Except for the Robocopy command line, you still can try GUI-based file synchronization software - AOMEI Backupper Professional. It supports Windows XP, Vista, 7, 8, 8.1,10 and 11(32-bit and 64-bit) and helps you sync two folders easily with the following options.
Besides, it still allows you to sync two folders to multiple destinations, such as local disk, external hard drive (HDD or SSD), CD/DVD, USB flash drive, network share or NAS, even to cloud drives like Google Drive, Dropbox, OneDrive, Box, etc.
To get started, please download AOMEI Backupper Professional and install it on a Windows PC. For server users, try AOMEI Backupper Server!
Step 1. launch AOMEI Backupper Professional on your Windows 10 computer, select Sync tab and then a method to sync two folders, here take Real-Time Sync as an example.
Step 2. Press + Add Folder button and then Share/NAS.
Step 3. Click Add Share or NAS Devices and then input the display name and network path to add the network share, and choose the folders you want to sync. You still need to type username and password if you receive error while adding network path.
Step 4. Click the triangle icon and tap Add Share or NAS Devices, type network path in the pop-up window and select another folder as destination.
Step 5. Hit Start Sync >> to sync two folders in real time in Windows. Optionally, you can click Options to comment the real time folder sync task, email or SMS notification, 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. It's the safest way to protect files, and meanwhile, it will take up the most disk space compared to other sync methods.
Of course, if you mind the disk space issue, you can also use other sync methods (eg: Mirror Sync) to sync files with daily, weekly, or monthly frequency, or based on event triggers, USB plug in. This can alleviate the disk space problem to some extent.
To completely resolve this issue, you could consider using the Backup feature to duplicate files. It not only schedules backup files but also deletes old backup images automatically to free up disk space. You have 3 options in following:
Besides, you still can choose to backup folders to AOMEI Cloud, a cloud drive with 1TB of free storage, and you have 15 days of free access to it after registration. And it enables you to run this task automatically, such as, daily, weekly, or monthly.
1. Can I schedule folder synchronization tasks using the Windows Task Scheduler and command-line tools?
Yes, you can schedule folder synchronization tasks using the Windows Task Scheduler in conjunction with the `robocopy` command-line tool. Simply create a new scheduled task, specify the `robocopy` command with the desired options and switches, and set the schedule for when you want the synchronization to occur.
2. Are there any precautions I should take before syncing folders using the command line?
Yes, it's essential to review and understand the `robocopy` options and switches you're using to ensure that the synchronization operation behaves as expected. Additionally, always double-check the source and destination paths to avoid accidental data loss or overwriting important files.
3. Are there alternative command-line tools or methods for syncing folders in Windows?
While `robocopy` is a powerful and commonly used command-line tool for folder synchronization in Windows, there are alternative tools available, such as `xcopy` and `rsync` (which can be used on Windows via third-party implementations). However, `robocopy` is often preferred for its robustness, flexibility, and built-in support in Windows environments.
4. How do I sync folders in batch file?
You can sync folders using a batch file by leveraging command-line tools such as robocopy or xcopy. Below is an example of how you can create a simple batch file to sync two folders using robocopy:
@echo off set source_folder=C:\path\to\source set destination_folder=D:\path\to\destination
robocopy "%source_folder%" "%destination_folder%" /mir
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, and 7. You can choose different sync methods and schedule settings based on your needs.
In addition, it still a professional backup software. If you don't want the files occupying much disk space, try the File Backup feature. And then, you can enable schedule backup, incremental or differential backup and automatic backup cleanup to manage backup task and disk space flexibly.