How to exclude files and folders copy using Robocopy on Windows 11, 10

Here are the steps to exclude one or more files and folders during a copy process using the Robocopy command-line tool on Windows 11.

Robocopy exclude files and folders command
Robocopy exclude files and folders command

UPDATED 8/2/2023: On Windows 11 (or 10), Robocopy (Robust File Copy) is a powerful file management command-line tool with many options to transfer files and folders to another location faster and more reliably than File Explorer.

However, by default, Robocopy transfers everything on a given path, which may not be ideal in every scenario as you may have specific files and folders in a location you don’t want to copy. However, the tool includes at least two options, which you can use to exclude files and folders from the copy process.

In this guide, you will learn how to copy data using Robocopy on Windows 10 (or Windows 11), excluding those files and folders you don’t need to transfer.

Exclude folder from Robocopy

To exclude a folder while copying with Robocopy, use these steps:

  1. Open Start on Windows 11.

  2. Search for Command Prompt, right-click the result, and select the Run as administrator option.

  3. 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

    This example excludes a specific folder using Robocopy:

    robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD exclude-folder-1

    This example excludes a folder using the Robocopy wildcard option:

    robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD exclude-fold*

    This example excludes multiple folders using Robocopy:

    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 complete the steps, the data will copy to the destination, except the folders specified in the command (exclude_folder_file_robocopy) will be excluded.

Exclude file from Robocopy

To exclude a file while copying with Robocopy, use these steps:

  1. Open Start.

  2. Search for Command Prompt, right-click the result, and select the Run as administrator option.

  3. 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

    This example excludes a file using Robocopy:

    robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF filename-1.extension

    This example excludes a file using the Robocopy wildcard option:

    robocopy C:\source\folder\path\ D:\destination\folder\path\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF filena*

    This example excludes multiple files using the Robocopy option:

    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 you complete 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.

Exclude files and folders from Robocopy

To exclude a file and folder using Robocopy, use these steps:

  1. Open Start.

  2. Search for Command Prompt, right-click the result, and select the Run as administrator option.

  3. Type the following command to copy the files and folders, excluding specific 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 complete the steps, all the content will copy to the new location except those files and folders you excluded in the command using the “/XD” and “/XF” switches.

Robocopy command switches

Robocopy has a lot of options, and in the command shown in this guide, we’re using the following switches to copy data, excluding specific files and folders.

  • /E — Copy Subdirectories, including empty ones.
  • /Z — Copy files in restartable mode.
  • /ZB — Uses restartable mode. If access is denied, use backup mode.
  • /R:5 — Retry 5 times (you can specify a different number. The default is 1 million).
  • /W:5 — Wait 5 seconds before retrying (you can select a different number. The default is 30 seconds).
  • /TBD — Wait for share names 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 location and file name.

The most important switches in this command are the “/XD,” which allows you to exclude folders, and “/XF,” which you can use to exclude files. The other options are optional, but you should use these options in any standard copy process using Robocopy.

About the author

Mauro Huculak is a Windows How-To Expert who started Pureinfotech in 2010 as an independent online publication. He has also been a Windows Central contributor for nearly a decade. Mauro has over 15 years of experience writing comprehensive guides and creating professional videos about Windows and software, including Android and Linux. Before becoming a technology writer, he was an IT administrator for seven years. In total, Mauro has over 21 years of combined experience in technology. Throughout his career, he achieved different professional certifications from Microsoft (MSCA), Cisco (CCNP), VMware (VCP), and CompTIA (A+ and Network+), and he has been recognized as a Microsoft MVP for many years. You can follow him on X (Twitter), YouTube, LinkedIn and About.me. Email him at [email protected].