Specifying File and Directory Names

By default, Robocopy assumes that any non-switch command-line argument is some form of file name, path, or wildcard. These may be intermingled with switch arguments, but the command line is easier to read if they are grouped together. The actual meaning of such a name depends on where they appear in the command in relation to any /XF or /XD switches.

The command line is parsed from left to right. There must be two non-switch arguments before any /XF or /XD switch, and these are taken to be the pathnames of the source and destination directories respectively.

Thereafter any non-switch argument is taken to be an Include Filespec - either a filename or wildcard (but not a path) naming one or more files (or sets of files) to include and consider as candidates for copying, until a /XF or /XD switch is found.

Note that if no Include Filespecs are found in the command line, a default of "*.*" (all files) is assumed. Also note that these Include Filespecs must be specified as individual arguments separated from other arguments by white space, and not appended to the source or destination directory pathnames as in, for example, the Xcopy command.

/XF (eXclude Files) informs the program that subsequent filenames, paths and wildcards are Files to exclude from copying (Exclude Filespecs rather than Include Filespecs), until a subsequent /XD switch is found.

/XD (eXclude Directories) informs the program that subsequent filenames and paths are Directories to exclude from copying (Exclude Dirspecs rather than Include or Exclude Filespecs), until a subsequent /XF switch is found.

Note the subtle differences in allowed values here :

ArgumentsNamesPathsWildcards

Source DirectoryYesYesNO

Destination DirectoryYesYesNO

Include FilespecsYesNOYes

Exclude FilespecsYesYesYes

Exclude DirspecsYesYesNO

Example : ROBOCOPY c:\source d:\dest *.c* /XF *.cpp /S /XD bin c:\source\unwanted

This command would cause Robocopy to walk the directory tree whose root is c:\source, except subdirectories named "bin", and the subdirectory c:\source\unwanted. Files whose extensions begin with "c" will be copied, except those whose extension is ".cpp".