Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Can you provide some examples of the paths in exclude.txt, including the path containing a space? – Velociraptors Jun 2 '11 at 17:51
up vote 4 down vote accepted

Reading through the relevant sections of the xcopy help

         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


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.

share|improve this answer
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 '11 at 20:35

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

share|improve this answer
didn't work........ – JoelFan Jun 2 '11 at 17:47

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.

share|improve this answer
didn't work........... – JoelFan Jun 2 '11 at 17:57
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. – Pär Björklund Jun 2 '11 at 18:09
Thanks Pär. I didn't realize that it could be disabled. – snapshoe Jun 2 '11 at 18:41

You must log in to answer this question.

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