Copy list of file names in text file

196 views Asked by At

I need to copy a list of files in a text file to a new directory, while preserving the directory structure. My file looks like this:

F326819.B88
F326819.B89
F326819.B90
F326731.B44
F326733.B61
F326733.B62

I need a batch command that will "pick" the ones listed in the text file and copy them over to a new directory, preserving the directory structure. I tried this code but it says invalid number of parameters:

for /f "delims=" %%i in (W:\GasImages\ServiceCards\WindLake.txt) do echo D|xcopy %%i "W:\GasImages\ServiceCards" "D:\Marc\WindLake" /i /z /y /e

Any help would be appreciated.

1

There are 1 answers

0
SomethingDark On

xcopy takes in a list of source files, followed by a destination directory. When there are multiple directories passed in, it doesn't know what to do with them all.

Try this (note that this code assumes the files to copy are in C:\GasImages\ServiceCards)

@echo off

for /f "delims=" %%I in (C:\GasImages\ServiceCards\WindLake.txt) do (
    xcopy "C:\GasImages\ServiceCards\%%I" "D:\Marc\Windlake\" /I /Z /Y /E
)

pause

Also, the echo D| is unnecessary with the /I flag.