Copying files listed in text file to new location

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mcusumano
Posts: 1
Joined: 19 Nov 2014 14:03

Copying files listed in text file to new location

#1 Post by mcusumano » 19 Nov 2014 14:07

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.

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Copying files listed in text file to new location

#2 Post by ShadowThief » 19 Nov 2014 14:50

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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Copying files listed in text file to new location

#3 Post by Ed Dyreen » 19 Nov 2014 15:01

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.

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Copying files listed in text file to new location

#4 Post by ShadowThief » 19 Nov 2014 15:41

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.

Post Reply