skelly9131
Programmer
Hi all, I'm teaching myself VBScript and have been able to get a script working that can read a single file and write certain records to an output file (code shown below).
What I can't figure how to do is modifiy this code to read multiple files in the same directory and write/append certain records to the same output file.
I've tried using the Files Collection Object, but I'm just not getting it yet. I've seen examples of scripts using things such as File.Name, but the book I'm using doesn't list all the properties available. Is there a master list of properties and their uses? Any help would be greatly appreciated.
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set folder = objFSO.GetFolder("c:\test\")
Set testfile = objFSO.OpenTextFile("c:\test\test.txt", ForReading)
Set outfile = objFSO.CreateTextFile("c:\test\testout.txt")
for each file in folder.Files
Do While Not testfile.AtEndOfStream
line = testfile.readline
linetype = left(line,4)
If linetype = "856A" Then
customer = mid(line,80,5)
End If
If customer = "2226 " or customer = "2227 " Then
outfile.writeline(line)
End If
Loop
MsgBox linetype
MsgBox line
MsgBox customer
next
testfile.close
outfile.close
What I can't figure how to do is modifiy this code to read multiple files in the same directory and write/append certain records to the same output file.
I've tried using the Files Collection Object, but I'm just not getting it yet. I've seen examples of scripts using things such as File.Name, but the book I'm using doesn't list all the properties available. Is there a master list of properties and their uses? Any help would be greatly appreciated.
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set folder = objFSO.GetFolder("c:\test\")
Set testfile = objFSO.OpenTextFile("c:\test\test.txt", ForReading)
Set outfile = objFSO.CreateTextFile("c:\test\testout.txt")
for each file in folder.Files
Do While Not testfile.AtEndOfStream
line = testfile.readline
linetype = left(line,4)
If linetype = "856A" Then
customer = mid(line,80,5)
End If
If customer = "2226 " or customer = "2227 " Then
outfile.writeline(line)
End If
Loop
MsgBox linetype
MsgBox line
MsgBox customer
next
testfile.close
outfile.close