# Can Windows' copy command handle multiple files?

On a Unix system, this command copies two files to a folder named folder:

cp foo bar folder


On Windows, this is not a valid command:

copy foo bar folder
The syntax of the command is incorrect.


Can I do this in one command on Windows, using its built-in tools?

-
Perhaps this is a job best left to Powershell. –  Kevin Panko Jul 27 '10 at 21:37

for %I in (file1.txt file2.txt file3.txt) do copy %I c:\somedir\


You can use this in either a batch file or directly from the command line. Not as clean as *nix, but it works.

-
I confirm that it works. Maybe if it was wrapped up into a batch file you could make it shorter? So that I would only need to type stevecopy foo bar [...] folder and it would do that loop automatically. –  Kevin Panko Jul 27 '10 at 15:34
I don't have to complete this 100% now, but for starters: for %%I in (%*) do copy %I c:\somedir\. Powershell may be a better fit for something like this, but that is an additional install. –  steve.lippert Jul 27 '10 at 16:00
Been working on it for far too long and still can't get something to work. Best I can do for you is the answer. –  steve.lippert Jul 27 '10 at 19:27
Thanks for the effort. I posted my version based on your idea. –  Kevin Panko Jul 27 '10 at 21:33
You will want to wrap your second %I in double quotes as a best-practice to handle spaces in the file name –  Goyuix Aug 3 '10 at 14:25

Windows includes robocopy built in, which copies multiple files from a single command:

robocopy a\source\folder a\dest\folder file1.docx file2.exe

-

Here is a short batch script to facilitate copying multiple files:

set FOLDER=%1

shift

for %%i in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do copy %%i %FOLDER%


Usage:

my-copy <DEST-FOLDER> source [source2, source3, ...]

-
better: for %%in (%*) do copy ... and then the number of in files is not limited to 10 (still limited, but 255 is a bit more head room :). Oh, and then you don't need SHIFT either. More: ss64.com/nt/syntax-args.html –  matt wilkie Jul 27 '10 at 23:06
Not sure if I understand -- do you mean to have copy %%i %1 ? That could work, but it would try to copy the first argument on top of itself, which would just create a harmless error message. –  Kevin Panko Jul 28 '10 at 2:52

Try

copy foo + bar folder

-
This is not what I wanted. This gives me one file, named folder\foo, with the contents of both foo and bar in it. I want to end up with folder\foo and folder\bar. –  Kevin Panko Jul 27 '10 at 15:19
This concatenates the files foo and bar. Its *nix equivalent is cat foo bar > folder –  ThatGraemeGuy Jul 27 '10 at 15:26
You mean cat foo bar > folder/foo –  Kevin Panko Jul 27 '10 at 15:28
Yup, looks like I was mistaken. If you have access to Powershell in your Windows environment, that might be looking into. Lots of the *nix commands carry over. –  Michael Jul 27 '10 at 15:32
Good point! I do have it. –  Kevin Panko Jul 27 '10 at 15:39