Using xcopy to copy multiple files/directories, some of which have spaces
Asked Answered
B

4

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?

Bash answered 12/4, 2011 at 0:10 Comment(2)
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?Downgrade
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 destPeriscope
B
22

Use quotes:

xcopy "d:\location\folder" /e 
Balky answered 12/4, 2011 at 0:22 Comment(1)
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]Bash
A
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.

Aeschylus answered 16/4, 2013 at 15:28 Comment(0)
M
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

Maritzamariupol answered 11/3, 2014 at 6:19 Comment(0)
C
-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...

Climacteric answered 4/9, 2015 at 4:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.