SHARE
Facebook X Pinterest WhatsApp

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

Jul 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 “\Servernamed$cronditappsrobocopylogs” “enough” “1”
‘This will search today, yesterday, day before yesterday files 
cscript SearchLog.vbs “C:Winntsyslogs” “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 =\server1d$cronditappsrobocopylogs”
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

Recommended for you...

What Backups Do I Have?
Gregory Larsen
May 12, 2021
Improving the Performance of a Table Variable using Optimizer Hint RECOMPILE
Gregory Larsen
Apr 1, 2021
TYPE Definition Change in Oracle 21c
Tip 74 – Changing Cost Threshold for Parallelism
Gregory Larsen
Feb 24, 2021
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.