Page 1 of 1

Copying files listed in text file to new location

Posted: 19 Nov 2014 14:07
by mcusumano
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.

Re: Copying files listed in text file to new location

Posted: 19 Nov 2014 14:50
by ShadowThief
I already answered this when you asked it on StackOverflow.

Code: Select all

@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

Re: Copying files listed in text file to new location

Posted: 19 Nov 2014 15:01
by Ed Dyreen
the error invalid number of parameters is generated by xCopy, you are feeding it 3 parameters, it requires you use only 2.

Code: Select all

@echo off

::--args--
set "$iFile=%~dp0tst.TXT"

::--macro--
set  ^"forLineR_=for /F delims^^=^^ eol^^= %%r in"

::--main--
%forLineR_% (

       'type "%$iFile%"'

) do   echo.xCopy/ZYIE "%~dp0%%~r" "D:\Marc\WindLake\%%~r"

pause
exit
hypothetical copy

Code: Select all

xCopy/ZYIE "Z:\ED\VIP\PROJ\dev\doskit\doskitXP32x86 v20140429\Hello world !\F326
819.B88" "D:\Marc\WindLake\F326819.B88"
xCopy/ZYIE "Z:\ED\VIP\PROJ\dev\doskit\doskitXP32x86 v20140429\Hello world !\F326
819.B89" "D:\Marc\WindLake\F326819.B89"
xCopy/ZYIE "Z:\ED\VIP\PROJ\dev\doskit\doskitXP32x86 v20140429\Hello world !\F326
819.B90" "D:\Marc\WindLake\F326819.B90"
xCopy/ZYIE "Z:\ED\VIP\PROJ\dev\doskit\doskitXP32x86 v20140429\Hello world !\F326
731.B44" "D:\Marc\WindLake\F326731.B44"
xCopy/ZYIE "Z:\ED\VIP\PROJ\dev\doskit\doskitXP32x86 v20140429\Hello world !\F326
733.B61" "D:\Marc\WindLake\F326733.B61"
xCopy/ZYIE "Z:\ED\VIP\PROJ\dev\doskit\doskitXP32x86 v20140429\Hello world !\F326
733.B62" "D:\Marc\WindLake\F326733.B62"
Druk op een toets om door te gaan. . .
don't know why you echo D{"ENTER"} into xCopy, i assume it's asking a question, i am running a non-english version so i can't know what question is being answered. i would use copy over xCopy for a file by file copy.

Re: Copying files listed in text file to new location

Posted: 19 Nov 2014 15:41
by ShadowThief
Ed Dyreen wrote:don't know why you echo D{"ENTER"} into xCopy, i assume it's asking a question, i am running a non-english version so i can't know what question is being answered. i would use copy over xCopy for a file by file copy.

If you specify a destination that doesn't exist, xcopy will ask if it's a (F)ile or a (D)irectory. You can use the /I flag to force xcopy to consider the destination a directory.