djhawthorn
Technical User
How would I go about searching for a specific word in a text file? At the moment I have this function:
Function LogFileSearch (LogFileLocation, SearchString)
TempChars = ""
SearchStringFound = false
If not WshFileSys.FileExists(LogFileLocation) Then
Msgbox "Could not open the log file " & LogFileLocation & ". Script will now exit.", VBOKonly + VBCritical, "Log File Search"
Wscript.Quit
End If
Set LogFile = WshFileSys.OpenTextFile(LogFileLocation)
Do While ((LogFile.AtEndOfStream <> True) and (TempChars <> SearchString))
TempChars = LogFile.Read(len(SearchString))
If TempChars = SearchString Then
SearchStringFound = true
End If
LogFile.SkipLine
Loop
LogFile.Close
LogFileSearch = SearchStringFound
End Function
Which sort of works, but is not quite functional (it only searches the first x characters in the text file from every line).
What I need is to search every word (words seperated by the space character) in every line, and when (if) it finds a match, it will return true. Can someone improve the above script, or point me in the right direction?
Function LogFileSearch (LogFileLocation, SearchString)
TempChars = ""
SearchStringFound = false
If not WshFileSys.FileExists(LogFileLocation) Then
Msgbox "Could not open the log file " & LogFileLocation & ". Script will now exit.", VBOKonly + VBCritical, "Log File Search"
Wscript.Quit
End If
Set LogFile = WshFileSys.OpenTextFile(LogFileLocation)
Do While ((LogFile.AtEndOfStream <> True) and (TempChars <> SearchString))
TempChars = LogFile.Read(len(SearchString))
If TempChars = SearchString Then
SearchStringFound = true
End If
LogFile.SkipLine
Loop
LogFile.Close
LogFileSearch = SearchStringFound
End Function
Which sort of works, but is not quite functional (it only searches the first x characters in the text file from every line).
What I need is to search every word (words seperated by the space character) in every line, and when (if) it finds a match, it will return true. Can someone improve the above script, or point me in the right direction?