I need to get robocopy to exclude any file whose path contains a directory with a particular name. For example, "bar":

c:\foo\bar\a.txt
c:\bar\c.txt
d:\baz\bar\flub\d.txt

should be excluded, but not

c:\foo\barf\b.txt

Here are the things I tried -- each of which was rejected by robocopy:

/XD \bar\
/XD *\bar\*
/XD *^\bar^\*

Any ideas?

link|improve this question

40% accept rate
feedback

1 Answer

Turns out the /XD matches on the directory name -- not the full path. So you don't actually have to worry about matching the backslashes.

So to exclude directories (anywhere in the path) called "bar", a simple /XD bar will work. If you wanted to exclude "barf", too, you could use /XD bar*.

Sometimes the answer is simpler than you think.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.