How to exclude files and folders copy using Robocopy on Windows 10
On Windows 10, Robocopy (Robust File Copy) is a powerful file management command-line tool with a slew of options to transfer files and folder to another location faster and more reliably than using File Explorer.
However, by default, Robocopy transfers everything on a given path, which may not be ideal on every scenario as you may have specific files and folders in a location that you don’t want to copy. Thankfully, the tool includes a least to switches that you can use to exclude files and folders from a copy process.
In this guide, you’ll learn the steps to copy data using Robocopy on Windows 10 but excluding those files and folders that you don’t need to transfer.
- How to exclude a folder using Robocopy
- How to exclude a file using Robocopy
- How to exclude a file and folder using Robocopy
How to exclude a folder using Robocopy
To copy a folder with its content but excluding a specific folder, do the following:
-
Open Start.
-
Search for Command Prompt, right-click the result, and select Run as administrator.
-
Type the following command to copy the files and folders excluding a specific folder to another location and press Enter:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD "C:\source\folder\path\to\exclude-folder"
Robocopy exclude folder command Exclude a folder using Robocopy alternative example:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD exclude-folder-1
Exclude a folder using Robocopy wildcard example:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD exclude-fold*
Exclude multiple folders using Robocopy example:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD "C:\source\folder\path\to\exclude-folder-1" "C:\source\folder\path\to\exclude-folder-2"
Once you’ve completed the steps, all the data from the path will be copied over excluding the folders you specified in the command exclude_folder_file_robocopy.
How to exclude a file using Robocopy
To copy a folder with its content but excluding a particular file, do the following:
-
Open Start.
-
Search for Command Prompt, right-click the result, and select Run as administrator.
-
Type the following command to copy the files and folders excluding a specific file to another location and press Enter:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF "C:\source\folder\path\to\folder\filename.extension"
Robocopy exclude file command Exclude a file using Robocopy alternative syntax example:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF filename-1.extension
Exclude a file using Robocopy wildcard example:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF filena*
Exclude multiple files using Robocopy example:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF "C:\source\folder\path\to\folder\filename-1.extension" "C:\source\folder\path\to\folder\filename-2.extension
After completing the steps, Robocopy will copy all the files and folders from a particular location excluding the files you specified in the command using the /XF switch.
How to exclude a file and folder using Robocopy
If you need to copy an entire folder but excluding a particular file and folder, do the following:
-
Open Start.
-
Search for Command Prompt, right-click the result, and select Run as administrator.
-
Type the following command to copy the files and folders excluding certain files and folders to another drive and press Enter:
robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD "C:\source\folder\path\to\exclude-folder" /XF "C:\source\folder\path\to\folder\filename.extension"
Robocopy exclude folder and file command
Once you’ve completed the steps, all the content will be copied to the new location except those files and folders you excluded in the command using the /XD and /XF switches.
Robocopy command switches explained
Robocopy has a lot of features, and in the command shown in this guide, we’re using the following switches to make copy data excluding certain files and folders.
- /E — Copy Subdirectories, including empty ones.
- /Z — Copy files in restartable mode.
- /ZB — Uses restartable mode, if access denied use backup mode.
- /R:5 — Retry 5 times (you can specify a different number, default is 1 million).
- /W:5 — Wait 5 seconds before retrying (you can specify a different number, default is 30 seconds).
- /TBD — Wait for sharenames To Be Defined (retry error 67).
- /NP — No Progress – don’t display percentage copied.
- /V — Produce verbose output, showing skipped files.
- /XD — Excludes folders matching the path and folder name.
- /XF — Excludes files matching the path and file name.
The most important switches in these command are the /XD that allows you exclude folders and /XF that you can use to exclude files. The other switches are optional, but they are recommended options that you should use in any standard copy process using Robocopy.
If you need additional help getting Robocopy to work, remember that you can submit your questions in the Pureinfotech forums.