3

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.

3 Answers 3

3

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

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%
1
  • The /XF switch is missing in your code. Even then, you are replicating the same OP code, wrapping it inside variables, so it won't work neither.
    – oscar
    Mar 15 at 13:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .