trad

How to exclude copied files and folders with Robocopy on Windows 10 • Pureinfotech

On Windows 10, Robocopy (Robust File Copy) is a powerful file management command line tool with many options to move files and folders to another location faster and more reliable compared to using File Explorer.

However, by default, Robocopy moves everything along a certain path, which may not be ideal in all cases as you may have specific files and folders in a location that you don’t want to copy. Copy. However, the tool includes at least two options that you can use to exclude files and folders from the copying process.

In this instruct, you will learn the steps to copy data using Robocopy on Windows 10, excluding files and folders that you don’t need to move.

How to exclude folders with Robocopy

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

  1. Open Begin on Windows 10.

  2. Search Command prompt, right-click the result and select Run as administrator Selection.

  3. Type the following command to copy files and folders except a specific folder to another location and press Into the:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD "C:sourcefolderpathtoexclude-folder"
    Robocopy directory exclusion command
    Robocopy directory exclusion command

    This example excludes a specific directory using Robocopy:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD exclude-folder-1

    This example excludes a directory using the Robocopy wildcard option:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD exclude-fold*

    This example excludes multiple directories using Robocopy:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD "C:sourcefolderpathtoexclude-folder-1" "C:sourcefolderpathtoexclude-folder-2"

After you complete the steps, the data will copy to the destination, except the directories specified in the command (lude_folder_file_robocopy) are excluded.

How to exclude files with Robocopy

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

  1. Open Begin.

  2. Search Command prompt, right-click the result and select Run as administrator Selection.

  3. Type the following command to copy files and folders except a specific file to another location and press Into the:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF "C:sourcefolderpathtofolderfilename.extension"
    Robocopy file exclusion command
    Robocopy file exclusion command

    This example excludes a file that uses Robocopy:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF filename-1.extension

    This example excludes a file that uses the Robocopy wildcard option:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF filena*

    This example excludes multiple files using the Robocopy option:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XF "C:sourcefolderpathtofolderfilename-1.extension" "C:sourcefolderpathtofolderfilename-2.extension

After you complete the steps, Robocopy will copy all the files and folders from a specific location, except the files you specified in the command using / XF transfer.

How to exclude files and folders with Robocopy

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

  1. Open Begin.

  2. Search Command prompt, right-click the result and select Run as administrator Selection.

  3. Type the following command to copy files and folders except specific files and folders to another drive and press Into the:

    robocopy C:sourcefolderpath D:destinationfolderpath /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD "C:sourcefolderpathtoexclude-folder" /XF "C:sourcefolderpathtofolderfilename.extension"
    Robocopy exclude directory and file command
    Robocopy exclude directory and file command

After you complete the steps, all the content will be copied to the new location except those files and folders you excluded in the command using / XD and / XF switches.

Explanation of Robocopy command switches

Robocopy has a lot of options and in the command shown in this tutorial we are using the following switches to make the copied data excluding specific files and folders.

  • /E – Copy Subfolders, including empty ones.
  • /Z – Copy files in rebootable mode.
  • /ZB – Use rebootable mode. If access is denied, use backup mode.
  • /R: 5 – Retry 5 times (you can specify another number, default is 1 million).
  • /W: 5 – Wait 5 seconds before trying again (you can choose another number, default is 30 seconds).
  • /TBD – Wait for the share name to be determined (retry error 67).
  • /NP – No Progress – does not show copied percentage.
  • /V – Produces verbose output, showing ignored files.
  • / XD – Exclude directories that match directory paths and names.
  • / XF – Exclude files that match the path and filename.

The most important switches in this command are / XD that allows you to exclude directories and / XF which you can use to exclude files. The other options are optional, but they are recommended options that you should use in any standard copying procedure using Robocopy.

Bouton retour en haut de la page
Fermer