dcsimg

Search for a string in today, yesterday or the day before's files

July 1, 2004



>>Script Language and Platform: VBScript, SQL Server
This VBScript allows you to search files that are a few days old, in a folder for a keyword. It is useful to search files like archived log files in the same folder so that you can look in to only those log files which have the keywords.

Usage:

'This will search todays and yesterdays files for a particular string.
cscript SearchLog.vbs "\\Servername\d$\crondit\apps\robocopy\logs\" "enough" "1"

'This will search today, yesterday, day before yesterday files 

cscript SearchLog.vbs "C:\Winnt\syslogs\" "Error" "2"

Author: MAK


'Author: MAK
'Objective: To search a string in all the files (2 days old) in a folder
'contact: mak_999@yahoo.com
'Date written: April 5, 2003
Set objArgs = WScript.Arguments
Const ForReading = 1 
Const ForWriting = 2 
set WshShell = WScript.CreateObject("WScript.Shell")
'strStartup = "\\server1\d$\crondit\apps\robocopy\logs\"
strStartup = objArgs(0)
'SearchString= "enough"
SearchString= objArgs(1)
noofdays=objArgs(2)
Set fso = CreateObject("Scripting.FileSystemObject")
Set fso2 = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(strStartup)
for each x in f.files
	if left(x.datelastmodified,10) >= left(date-noofdays,10) then
		filenamepath=strStartup + x.name
		Set ReadFile = fso2.OpenTextFile(filenamepath, ForReading, TristateFalse) 
		thisTXT =	ReadFile.ReadAll 

		ValueSearch = InStr(1,thisTXT,SearchString,1) 
			If ValueSearch>=1 Then 
				msgbox  "Found '"+ Searchstring + "' in "+ filenamepath
			end if
	end if
next
msgbox "Completed"

Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers