Page 1 of 1

read simultialy from two files

Posted: 12 Jul 2009 03:44
by yossibr
Hi ta all,

I need
to read simultialy from two files

example :
one from par1 and one from par2

for /f %%i in (par1 ) do (
echo ------ %%i ------
)

for /f %%z in (par2) do (
echo ++++++ %%z ++++++
)

thanks .

Posted: 12 Jul 2009 05:16
by ghostmachine4
assuming your files are of the same number of lines, here's a vbscript

Code: Select all

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile1 = "c:\test\file.txt"
strFile2 = "c:\test\file2.txt"
Set objFile1 = objFS.OpenTextFile(strFile1)
Set objFile2 = objFS.OpenTextFile(strFile2)
Do Until objFile1.AtEndOfLine
   strLine1 = objFile1.ReadLine
   strLine2 = objFile2.ReadLine
   WScript.Echo strLine1 & "->" & strLine2
Loop
objFile1.Close
objFile2.Close


output

Code: Select all

C:\test>more file1.txt
1
2
3
4

C:\test>more file2.txt
a
b
c
d

C:\test>cscript /nologo test.vbs
1->a
2->b
3->c
4->d


Posted: 12 Jul 2009 05:21
by yossibr
ghostmachine4 , thank tou for your quick answer .
This script must br run under dos command only .

Posted: 14 Jul 2009 11:53
by avery_larry
What do you want to do? Output alternating lines from the 2 files? Jumble the output together in whatever order happens?