11

i want to copy multiple files at once through xcopy. is it possible. i mean something like:
xcopy file1+file2+file3 destinationfolder
any help is appreciated :)

Scott Lawrence
  • 6,993
  • 12
  • 46
  • 64
sushant
  • 923
  • 5
  • 17
  • 33

4 Answers4

13

I don't think it's possible with a single xcopy, but you could use a for statement.
Something like:
for %f in (file1, file2, filen) do xcopy %f dest\

Andrew
  • 635
  • 5
  • 11
  • i dont know how to use it. can u plz give the exact syntax? that would be really helpful – sushant Apr 08 '10 at 06:19
  • this *is* the answer. The for command iterates through the list of files (specified in brackets) and executes the command that appears after the "do" keyword. Try typing `for /?` on the command line for more information – Andrew Apr 08 '10 at 06:35
  • 2
    To use the FOR command in a **batch** program, specify **%%variable** instead of %variable. Variable names are case sensitive, so %i is different from %I. – Behzad Ebrahimi Dec 14 '20 at 08:25
3

for %f in (file1,file2,file3) do xcopy %f destinationfolder

Midhat
  • 17,454
  • 22
  • 87
  • 114
  • To use the FOR command in a **batch** program, specify **%%variable** instead of %variable. Variable names are case sensitive, so %i is different from %I. – Behzad Ebrahimi Dec 14 '20 at 08:25
1

if your files starts with a specific pattern, you can use wildcards (eg text files that starts with file)

copy file*.txt e:\destination
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
1

I used the following for copying hundreds of files and filtering them by file extension. Below I am saying give me all files with the file extension .dll, .exe, or .pdf

for %f in (dll,exe,pdf) do xcopy /s /i C:\source\*.%f C:\destination
Vega
  • 27,856
  • 27
  • 95
  • 103
D1v3
  • 101
  • 1
  • 11
  • To use the FOR command in a **batch** program, specify **%%variable** instead of %variable. Variable names are case sensitive, so %i is different from %I. – Behzad Ebrahimi Dec 14 '20 at 08:25