1.

Solve : batch file that read from a txt file line by line?

Answer»

Hi All

I have little or no experience using batch FILES

I need to know how to do the following:

i have the text file (list_of_files.txt) with the contents:

C:\myfolder\file1.txt
C:\myfolder\file2.txt
C:\myfolder\file3.txt
C:\myfolder\file4.txt

I need a batch file to read the contents of the text file and copy the files listed in the text file to a specified folder and append something to the end of the file name

EG copy C:\myfolder\file4.txt C:\myfolder2\file4.txt_OLD

The reason I am doing this is the contents of list_of_files.txt may change.

regards
G. Code: [Select]echo off

set folder=C:\myfolder2

for /f "tokens=*" %%A in (list_of_files.txt) do (
echo. copy %%A %folder%\%%~nA_OLD
)
pause
test it and then remove echo. from 6 line Hey

That's a good solution but not really right

the first bit is good

I've figure that out ALREADY since I posted

for /f "tokens=*" %A in (list_of_files.txt) do copy %A C:\myfolder2

I need to keep the names of the files correct

you script rename everything to 1_OLD as opposed to file1.txt_OLD

I THINK I'm gonn have to do a 2 parter

so something like:

Code: [Select]for /f "tokens=*" %A in (list_of_files.txt) do copy %A C:\myfolder2

cd C:\myfolder2

for /everyfile %b do move %b %b_OLDfigured it out

%~nxA
Good to see this forum is going well and strong.

Here is an alternate solution script in biterscripting ( http://www.biterscripting.com ) .

Code: [Select]var str list ; cat "list_of_files.txt" > $list
while ($list <> "")
do
    # Get the next file. Get just the file name after the last /.
    var str file, name ; lex "1" $list > $file ; stex -p "^/^l[" $file > $name
    # New name is $name+"_OLD". Copy the file with new name to folder C:\myfolder2.
    system copy ("\""+$file+"\"") ("\"C:\myfolder2\"+$name+"_OLD\"")
done

J



Discussion

No Comment Found