VB script to merge logs files together
Posted on 2006-06-25
We've got several 100 .log files from an auditing script/program & we want to merge them into one continueous file.
each log file is named [machinename].log and contains a single line with the audit info in.
The output file would have each of these single lines, so that it is easy to import into excel/etc
My first up attempt at a script goes like this:
Const FOR_READING = 1, FOR_WRITING = 2
Set fso = CreateObject ("Scripting.FileSystemObject")
Set folders = fso.GetFolder("c:\audit")
set files = folders.files
Set outputFile = fso.openTextFile("c:\audit\logs.txt", FOR_WRITING)
For Each file In files
IF right(file.name,4) = ".log" THEN
Filename = "C:\audit\" & file.name
inputFile = fso.OpenTextFile(filename, FOR_READING)
Do While inputFile.AtEndOfStream <> True
retstring = inputFile.ReadLine
The logic behind the script is
- look in c:\audit
- for each file in that folder
-- open that file
-- read in contents
-- output line to single output file
but it fails on the opening of the inputFile with
Microsoft VBScript runtime error: Object doesn't support this property or method: 'inputFile'
If VBS doesn't let you assign and use variables in place of the filename in OpenTextfile methods, then how should be script do the logic stated above?
This is probably fairly easy - I'm only just starting out teaching myself VBS - but its urgent, so I'm going to assign max points for it! ;)
Update: I've put "set xyz =" and am gettign a bit further.
Fails with a Microsoft VBScript runtime error: Object required: '[string: "C:\audit\1318AKGCR.l"]'
(where "C:\audit\1318AKGCR.l" is most fo teh filename of one of my log files (shoudl be C:\audit\1318AKGCR.log)