Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
Database Tools
SQL Scripts & Samples
» Database Forum
» Slideshows
» Sitemap
Free Newsletters:
News Via RSS Feed

follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles

SQL Scripts & Samples

Posted Jul 1, 2004

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

By Staff

>>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.


'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
'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)
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 +
		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
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

SQL Scripts & Samples Archives

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Latest Forum Threads
SQL Scripts & Samples Forum
Topic By Replies Updated
sql help!! add 1 August 22nd, 11:58 AM
How To Combine These 2 Queries into 1 Query ? tarek_land 1 June 7th, 08:37 AM
solving query svibuk 1 February 3rd, 06:08 AM
converting from a character string to uniqueidentifier saturnius 4 January 4th, 05:56 AM