Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searchingfor string in a file with different names

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Joined
Jan 15, 2009
Messages
80
Location
GB
Hi,

I have a requirement to search through an error log for a string. I am using some monitoring software to look for errors in a file but the file name will change. E.G from error12052010.log to error13052010.log over night.

I have the code to search through a static file name but need it to handle changes

Const ForReading = 1

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "hello"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\test\string.txt", ForReading)

Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count > 0 Then
Wscript.Echo 0
Else Wscript.Echo 1
End If
Loop



I was thinking that maybe the file name needs a date function but I am not sure teh date format in VBscripot is the same as the format of the file I need to check
 
[tt]'the starting point is a variable of Date type
'how do you obtain it does not matter
'this is an example
dt=#2010-05-12 13:15:00#
wscript.echo dt 'how it is displayed does not matter

yyyy=year(dt)
mm=month(dt)
dd=day(dt)
wscript.echo yyyy & vbcrlf & mm & vbcrlf & dd

mm=right("00" & mm,2)
dd=right("00" & dd,2)
wscript.echo yyyy & vbcrlf & mm & vbcrlf & dd

'take an example of today
dt=now()
yyyy=year(dt)
mm=right("00" & month(dt),2)
dd=right("00" & day(dt),2)
s=dd & mm & yyyy 'your needed format
wscript.echo s
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top