VB script to merge logs files together

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:

Dim fso


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
         'wscript.echo restring


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)

Who is Participating?
Mark_FreeSoftwareConnect With a Mentor Commented:

try this one:


Dim fso
Set fso = CreateObject ("Scripting.FileSystemObject")
Dim ffolder
Set ffolder = fso.GetFolder("c:\audit")
Dim ffiles
Set ffiles = ffolder.files
Dim ffile
Dim sFileName
Dim sInputFile
Dim retString
Dim sOutPutFile
Set sOutPutFile = fso.OpenTextFile("c:\audit\logs.txt", FOR_WRITING)

For Each ffile In ffiles
  If Right(ffile.Name, 4) = ".log" Then
    sFileName = "C:\audit\" & ffile.Name
    Set sInputFile = fso.OpenTextFile(sFileName, FOR_READING)
      Do While sInputFile.AtEndOfStream <> True
         retString = sInputFile.ReadLine
         'wscript.echo restring
         sOutPutFile.WriteLine (retString)
         retString = ""
  End If


as you can see i've used some different var names (ffiles for example)
that is because i tested this code in vb
and vb bombs out when reserved words are used
RinceNZAuthor Commented:
Hi Mark,
Thanks for that - thats got it.... you've got the points! ;)
(Looks like it was a reserved words issue.... I told you I was teaching myself!)

But if you could help with one more little thing, it'd be really appreciated.
The log files are sort of in a xml-type format, so it's a bit messier than I first thought.
eg all on a single line, I have entries like "<hostname>1544wnpc</hostname>" and what I'm ultimately heading towards is a single file (tab/comma delimited) and one of the columns is "hostname"

I've managed to find the original audit script, and I'm right re the XML - its generated via (to continue using "hostname" as the example):
objXMLDoc = CreateObject("Microsoft.XMLDOM")
hostnameTag = objXMLDoc.createElement("hostname")

so is there some way to re-engineer XML elements back into "pure" text? Even just a hint on the items to google for will be fine! (like I said, you've doen 99.9% enough to be rewarded the assigned points!)
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


normally i don't use the microsoft.xmldom stuff,

i always go for the pure vb Mid, Left, right and instr functions.

so i can't help you with that xml api's,

i can (if you want)

write a script that will convert one document to another

but to write it, i need some pieces text to practise with
RinceNZAuthor Commented:
ahhh - thats what I thought....
I'm pretty sure I could nut something out with mid/left/right/instr as well
might try a bit of a google first though to get my head around xmldom

cheers. points awarded.

thanks for the points
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.