Hi all
I have two parts of code; one is searching (InStr) if log file contains certain string and the other one find the last modified log in one folder.
Now I would like to merge these two together and modify so the script finds the last modified log file from all the logs in folder that contain certain string.
These are the two code snipets:
1. finds a string in log file:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set folder = objFSO.GetFolder("C:\folder\")
for each file in folder.Files
if lcase(objFSO.getExtensionName(file.path))="log" then
Set myFile = objFSO.OpenTextFile(file.path, ForReading)
Do While Not myFile.AtEndOfStream
myLine = myFile.ReadLinemyLine = myFile.ReadLine
If InStr(myLine, "string 2 search for") Then
'action 1
else
'action 2
End If
Loop
myFile.close
end if
next
2. Finds the last modified log in logs folder:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set FolderToScan = objFSO.GetFolder("C:\folder\")
dim filesys, text, readfile, contents, FilePath
Set objFolder = objFSO.GetFolder(FolderToScan)
NewestFile = ""
NewestDate = #1/1/1970#
For Each objFile In objFolder.Files
if lcase(objFSO.getExtensionName(objFile.path))="log" then
If objFile.DateLastModified > NewestDate Then
NewestDate = objFile.DateLastModified
NewestFile = objFile.Name
FilePath = objFile.Path
End If
end if
next
WScript.Echo NewestFile
Any help would be appreciated.
tnx