2

I'm trying to use xcopy /exclude:exclude.txt and one of the paths in exclude.txt has a space in it and it's not working. Is there any workaround for this?

1
  • Can you provide some examples of the paths in exclude.txt, including the path containing a space? Jun 2, 2011 at 17:51

3 Answers 3

4

Reading through the relevant sections of the xcopy help

/EXCLUDE:file1[+file2][+file3]...
         Specifies a list of files containing strings.  Each string
         should be in a separate line in the files.  When any of the
         strings match any part of the absolute path of the file to be
         copied, that file will be excluded from being copied.  For
         example, specifying a string like \obj\ or .obj will exclude
         all files underneath the directory obj or all files with the
         .obj extension respectively.

We can see that the exclude option is not working on paths or file names but "filters". To illustrate this I'll try to give a short example. Picture this exclude.txt

Unicorns
Dolphins

This will filter out any file that has unicorns or dolphins anywhere in its name. e.g Dolphins.txt will be filtered but Ponys.txt will be fine.

To get back to your issue. The reason that your filter isn't matching isn't because of the space in the path. By default xcopy will only care about the filename and not the full path, any filter you have that includes a full path will not match and the file will get copied.

You can change this behavior of xcopy by supplying the /f flag in your command. This should solve the issue you're seeing.

1
  • Wow! /f works, but it this effect is totally undocumented! It is supposed to only affect printing messages, not how it interprets the Exclude file!
    – JoelFan
    Jun 2, 2011 at 20:35
1

Edit exclude.txt and put double quotes around the path that contains a space.

0
0

One thing I've done in this situation is to use the "short name" (old style DOS 8.3 name). You can get this name with dir /x. Every Windows version since Win 95 that has allowed long file names has also allowed this alternate 8.3 name for files/dirs.

2
  • using short file names can fail. By default windows creates short file names but it's possible to disable this using the fsutil tool. It's often suggested in tweaking guides to disable this so it's not something you want to design for.
    – Paxxi
    Jun 2, 2011 at 18:09
  • Thanks Pär. I didn't realize that it could be disabled.
    – snapshoe
    Jun 2, 2011 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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