Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 663
M Thomas Avatar asked Apr 12 '11 00:04

M Thomas


People also ask

How copy multiple files using xcopy?

To append files, specify a single file for destination, but multiple files for source (that is, by using wildcards or file1+file2+file3 format). If you omit destination, the xcopy command copies the files to the current directory.

What option allows you to copy all the files and directories including the empty directories?

To do so, run the Xcopy command with /T switch. Using the /T switch will cause Xcopy to copy only the directory tree structure to the destination but ignores the empty directories. You can also add the /E switch to the command to include empty directories, as shown in the example command below.

Can xcopy copy directories as well?

MS-DOS and Windows command line By default, the basic xcopy command only copies files in the directory you specify as the source directory. You must use the /E option to copy subdirectories in the source directory as well.


2 Answers

Use quotes:

xcopy "d:\location\folder" /e  
like image 198
Ken White Avatar answered Oct 14 '22 16:10

Ken White


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.

like image 24
Juan González Avatar answered Oct 14 '22 15:10

Juan González