Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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


should be excluded, but not


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

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

Any ideas?

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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