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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open multiple files from 1 folder and combine the data

Status
Not open for further replies.

tumor

Programmer
May 2, 2002
7
0
0
US
I would like to know if its possible to open multiple files from one folder and add the contents of the file to the same file.

say each file has different numbers in it and i want to add those numbers and save them to one file
 
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("C:\file1.txt",1)
nVar = CDbl(oFile.ReadAll)
oFile.Close
Set oFile = oFSO.OpenTextFile("C:\file2.txt",1)
nVar = nVar + CDbl(oFile.ReadAll)
oFile.Close
Set oFile = oFSO.OpenTextFile("C:\file3.txt",2,True)
oFile.WriteLine nVar
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top