1

Instead of running xcopy 6 times, is there a way to define an array of files to copy?

xcopy \\\from_location\\(A,B,C,D,E)*.txt \\\to_location\

1

3 Answers 3

1

Not with just XCOPY. But a simple FOR statement can help:

for %A in (A B C D E) do xcopy "fromPath\%A*.txt"  "toPath"
0

I'm not sure of any native ways to do this, but you can see this post for information about a GUI and command-line tool that has about every conceivable way to rename files with patterns.

If you use the command-line version of this tool and add it to your PATH, you should be able to use it from a batch file.

0

MaQleod's link provides a Powershell answer, but if you're interested in a batch script answer, here's one way to do it:

@echo off
set __fileset.1=a*.txt
set __fileset.2=b*.txt
set __fileset.3=c*.txt
set __fileset.4=d*.txt
set __fileset.5=e*.txt

for /f "tokens=2* delims=.=" %%g in ('SET __fileset.') do call :CopySet "%%h"
goto :exit

:CopySet
echo xcopy "%~dpxn1" "\to_location\." /v
goto :eof

:exit

By using the __fileset. environment variables, you are creating a pseudo array in a batch file. You then use the for loop to walk-thru all the available values, and you call the sub CopySet to perform the actual copy command. Of course, the script can be enhanced, but this is just an example on how to do this.

Make sure that the last line in the batch script is empty, as that's used by the goto :eof command to end the sub and return to the previously calling line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .