Free Newsletters:
DatabaseDaily  
Database Journal
Search 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 SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» DBA Jobs
» Sitemap

News Via RSS Feed


follow us on Twitter





New Security Features Planned for Firefox 4

Another Laptop Theft Exposes 21K Patients' Data

Oracle Hits to Road to Pitch Data Center Plans
Database Journal |DBA Support |SQLCourse |SQLCourse2









Systems Programmer / Software Engineer - C, Unix-Linux, Multi-threading, IPC
WSI Nationwide, Inc.
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Featured Database Articles

SQL Scripts & Samples

Jul 1, 2004

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

By DatabaseJournal.com 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.

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

Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

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