Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have tried to specify an /EXCLUDE filename with spaces in it to xcopy, but it always chokes. How can I specify such a path to xcopy without copying the /EXCLUDE files into the current directory and without using the old DOS ~1 shortname hack?

c:\Users\binki\Documents\repos\xcopy_exclude_spacey>dir source
 Volume in drive C is OS
 Volume Serial Number is 7C4E-86D4

 Directory of c:\Users\binki\Documents\repos\xcopy_exclude_spacey\source

2013-01-03  16:39    <DIR>          .
2013-01-03  16:39    <DIR>          ..
2013-01-03  16:39                 0 a
2013-01-03  16:39                 0 a b c
2013-01-03  16:39                 0 b
2013-01-03  16:39                 0 c
               4 File(s)              0 bytes
               2 Dir(s)  117,279,027,200 bytes free

c:\Users\binki\Documents\repos\xcopy_exclude_spacey>type "various exclude rules\a"
a

c:\Users\binki\Documents\repos\xcopy_exclude_spacey>xcopy /E /EXCLUDE:"various exclude rules\a" source dest
Can't read file: "various exclude rules\a"

0 File(s) copied

c:\Users\binki\Documents\repos\xcopy_exclude_spacey>xcopy /E "/EXCLUDE:various exclude rules\a" source dest
Invalid number of parameters

None of the ways of quoting the filename which would work fine in a decent shell work for me with xcopy. For some reason, "/EXCLUDE:<filename>" syntax prevents the option itself from being recognized. The other syntax, "/EXCLUDE:"<filename>", causes the message Can't read file: "<filename>" to be printed, showing that the option is being parsed correctly: the double-quotes are preventing the argument from being split up into multiple parts. However, this message suggests that the double-quotes are not being properly stripped from the filename by xcopy before it tries to open the file.

It seems, from this, that if the first component of the path I specify in /EXCLUDE started with a " and my /EXCLUDE filename ends in ", I would be able to reference that file from xcopy’s /EXCLUDE option successfully. But Windows refuses to let me place the " character in my filename.

So, how do I use xcopy in a modern world with spacey filenames?

share|improve this question
1  
xcopy is a pretty old program. Easy suggestion, stop using filenames with spaces....they are a pain to deal with generally in all OSen as they tend to be argument seperators. –  mdpc Jan 3 '13 at 22:29
    
All OSes other than Windows seem to use something like a POSIX shell and environment which has a well-enough-defined method for specifying file paths with spaces. Windows apparently doesn’t have a way to truly pass multiple arguments to a launched program but passes the arguments as a flat string, meaning argument delimitation happens at the wrong time. But Windows is the OS where spaces in path names are most common, so there must be a solution to this problem, especially since the xcopy in Windows 8 cannot be the same xcopy in Windows 98. –  binki Jan 4 '13 at 5:47
    
I suppose, however, that robocopy probably works in this situation and is available as long as you’re targetting a modern Windows. –  binki Jul 16 at 13:38
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.