Click here to Skip to main content
15,887,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to develop vb script to continuously read a log file dumping from another application and if a certain string exists,then my script should show found. I already have code which can parse for a particular string in a text file
VB
Const ForReading   = 1
Const ForWriting   = 2
Const ForAppending = 8
Dim intEqualPos
Dim objFSO, objIniFile
Dim strFilePath, strKey, strLeftString, strLine
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
ReadIni     = ""
strFilePath = Trim( myFilePath )
strKey      = Trim( myKey )
If objFSO.FileExists( strFilePath ) Then
    Set objIniFile = objFSO.OpenTextFile( strFilePath, ForReading, False )
    Do While objIniFile.AtEndOfStream = False
        strLine = Trim( objIniFile.ReadLine )
        ' Check if section is found in the current line
            ' Parse lines until the next section is reached
            Do While Left( strLine, 1 ) <> "["
                ' Find position of equal sign in the line
                intEqualPos = InStr( 1, strLine, "=", 1 )
                If intEqualPos > 0 Then
                    strLeftString = Trim( Left( strLine, intEqualPos - 1 ) )
                    ' Check if item is found in the current line
                    If LCase( strLeftString ) = LCase( strKey ) Then
                        parseTextFile = Trim( Mid( strLine, intEqualPos + 1 ) )
                        ' In case the item exists but value is blank
                        If parseTextFile = "" Then
                            parseTextFile = " "
                        End If
                        ' Abort loop when item is found
                        Exit Do
                    End If
                End If
                ' Abort if the end of the INI file is reached
                If objIniFile.AtEndOfStream Then Exit Do
               ' Continue with next line
                strLine = Trim( objIniFile.ReadLine )
            Loop
        Exit Do
    Loop
    objIniFile.Close
Else
Echo (strFilePath & " doesn't exists. Exiting...")
    Wscript.Quit 1
End If

Will above code work i need to do some modification for real time parsing?
Posted
Updated 16-Dec-14 4:51am
v2
Comments
Sergey Alexandrovich Kryukov 16-Dec-14 10:37am    
It more depends on dumping method than on that reading code. The dumping should be performed on the file with shared access.
—SA
Richard MacCutchan 16-Dec-14 11:51am    
Why not try it and see what happens? It's unlikely that we can guess whether it will do what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900