Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining multiple text files into one text files

Status
Not open for further replies.

lavadan

Programmer
Dec 17, 2007
49
US
Hi All,

I have a question in VB script as i am new to scripting.

I have 15 text files like t1.txt,t2.txt....t15.txt.

Each text files have some account numbers in them. For ex
t1.txt has 25 account numbers like 12300,12301..12325 and similarly for t2.txt, t3.txt...t15.txt.

I have to combine the contents in all text files into one single text file.

Can someone help me with this coding. The idea i have is

Open the folder that contains these text files.
Open the first text file.
Read the content of the first text file and write it to new text file(say total.txt)
Open the second text file.
Read the content of the second text file and write it to total.txt
Repeat the same procedure till you hit the last text file.
 
This is not a vbscript solution, but an alternate way you may find handy is to try this in a command window or batch file:

copy t1.txt+t2.txt+t3.txt+...+t15.txt total.txt
 
Please read up on the link that PHV posted but this should get you started. Just make this a function and pass it all of the input files you want in your target output file.

Code:
fso.OpenTextFile(tarFile, ForAppending, True).Write (fso.OpenTextFile(InFile).ReadAll)

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top