Find the text in Vbscript

vbscript

I am looking for help to read a log file, where the log file has current date inside the log and I wanted to read from there all the line and look for a error to output the error with current date.

My Sample Log file

[10/12/2012 testing the app1
[10/13/2012 testing the app2
[10/14/2012 testing the app3
[10/15/2012 testing the app4

My unfinished vbscript:

Const ForReading = 1

Dim strSearchFor

strSearchFor = "currentdate in the log file"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading)

strLine = objTextFile.ReadLine

If log contains (inside mylogfile.log file the) current date then ' I am looking help to write the code here...

  Wscript.Echo "we found current date"

Else

  Wscript.Echo "We did not found current date"

End If

Looking for help in this… Thanks lot…. in advance…

Best Answer

InStr will find a substring within a string

Const ForReading = 1

Dim strSearchFor
strSearchFor = "currentdate in the log file"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading)

do until objTextFile.AtEndOfStream
    strLine = objTextFile.ReadLine()

    If InStr(strLine, strSearchFor) <> 0 then
        Wscript.Echo "we found current date"
    Else
        Wscript.Echo "We did not found current date"
    End If
loop
objTextFile.Close
Related Topic