23

I'm trying to use xcopy to copy over several files and directories onto an external hard drive. The following command works fine...

xcopy d:\location\folder /e 

... except it's not copying over any files/directories withing d:/location/folder that have spaces. I understand that Windows requires file names with spaces need to be enclosed in quotes, but what do I do if I'm trying to do a huge recursive copy where there may be several files or folders with spaces in the name?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
MT3
  • 1,065
  • 3
  • 13
  • 22
  • 1
    Hmm, I cannot reproduce this issue: the command just works as expected, also with your [d:\location\folder\anotherfolder\folder with spaces] structure… Does it have the Archive, Hidden or System attribute somewhere? Do the switches /A, /H, /F or /L help in any way to understand what goes wrong? Are you copying to any special target? – mousio Apr 12 '11 at 19:29
  • 1
    I've been using xcopy for several years. It works fine with spaces. Sometimes if the resulting folder+filename combination is too long, it complains. Like mousio said, it could be attributes or empty files. Try using these flags: xcopy /y /d /e /f /h /k source dest – Vik David Apr 18 '11 at 10:55

4 Answers4

22

Use quotes:

xcopy "d:\location\folder" /e 
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Hmm, I tried that, but still the same thing. It doesn't copy folders within that directory that have spaces. For example: [d:\location\folder\anotherfolder\folder with spaces] – MT3 Apr 12 '11 at 00:55
3

You should use quotes the following way:

xcopy "d:location\folder\anotherfolder\folder with spaces"

Note the unit letter and the colon go outside the quotes and no \ at the beginning either.

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
Juan González
  • 1,526
  • 3
  • 16
  • 32
0

This may not be the answer to your questions, but an alternative to xcopy is robocopy. See the following xcopy about subdirectories.

http://ss64.com/nt/xcopy.html

Additionally if there are spaces in the source or target directories. Then you should wrap them in quotes ("). For example:

xcopy "soure path with spaces" "targetPath"

Cheers

Alfabravo
  • 7,493
  • 6
  • 46
  • 82
hmadrigal
  • 1,020
  • 11
  • 19
-3

The example given makes me uneasy. Maybe needlessly, but my read on the Win cmd.exe window (using [] to enclose related bits :^) is: [command] [d:\location\folder] [DESTINATION DRIVE:LOCATION:FOLDER] [/E]

Maybe lower-case /e, works as well, maybe in implied destination to present location works. When I type "help xcopy" is lists the command name, the source, and the destination and the /Upper Case Switches. Yes, destination is optional. But when results don't match your expectation, dropping back to the canonical form, with every jot and tittle in place, seems like a stronger start. One can focus on the thing that's not working.

The help example doesn't use it, but I also feel a bit safer if its clear that the literal path given is the stem and explicitly put in a wildcard:

C:>xcopy /E C:\Backup* C:\ToyVmBackup
C:\Backup\Backup_VM1_2015-08-27T221110.vbk
C:\Backup\Backup_VM2_2015-08-31T221227.vbk
C:\Backup\VeeamConfigBackup\SVC-L7-WABBOTT\SVC-L7-WABBOTT_2015-08-24_10-00-15.bco
3 File(s) copied

Ok, I prefixed the /E and got away with it. Its ambiguity I'm trying to control, as long as /E starts with a '/' it won't be taken for a path...

Bill IV
  • 195
  • 2
  • 11