2

I'd like to exclude all files matching C:\dir1\*.ext so I say:

robocopy C:\dir1 C:\dir2 /E /B /MIR /xf C:\dir1\*.ext

According to the documentation this should work:

/xf <FileName>[ ...]

Excludes files that match the specified names or paths. Note that FileName can include wildcard characters (* and ?).

But it results in:

ERROR : Invalid Parameter #16 : "xyz"

How can I exclude based on this pattern? Excluding by directory or by file name pattern is not specific enough.

boot4life
  • 269
  • 2
  • 5
  • 12

3 Answers3

2

I guess you're missing a subfolder there, like in:

robocopy C:\dir1 C:\dir2 /E /B /MIR /xf C:\dir1\subdir\*.ext

Otherwise, this should work:

robocopy C:\dir1 C:\dir2 /E /B /MIR /xf *.ext

From my experience, /xf can use the wildcard just for names, and not for paths. I don't think it's possible that mix.

As a workaround, you may launch robocopy twice:

robocopy C:\dir1 C:\dir2 /E /B /MIR /xd C:\dir1\subdir\
robocopy C:\dir1\subdir C:\dir2\subdir /E /B /MIR /xf *.ext
curropar
  • 601
  • 3
  • 17
1

According to the documentation at https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy:

/xf <FileName>[ ...] Excludes files that match the specified names or paths. Note that FileName can include wildcard characters (* and ?).
/xd <Directory>[ ...] Excludes directories that match the specified names and paths.

So this specifically means that wildcard can be used in the /xf flag but not in the /xd flag.

PeterS
  • 131
  • 2
0

You can read more about robocopy syntax :

set _src="C:\dir1"
set _dst="C:\dir2"
set _option=/E /B /MIR
set _xf="C:\dir1\subdir\*.ext"

robocopy %_src% %_dst% %_option% %_xf%
Haim Cohen
  • 11
  • 2