I'm trying to fix some scripts that someone else wrote before I worked here. We want to search all files on specified computers for a specified string, but we only want to search files that have been modified within a certain amount of days. There are two scripts involved.
First Script
Second Script
Thanks for any help.
First Script
Code:
on error resume next
Const ForReading = 1
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
srcTXT = "C:\scripts\accessed.txt"
Set objFileSrc = objFSO.OpenTextFile(srcTXT, ForReading)
daysOld = InputBox("How many days ago was the file modified?")
SearchString = InputBox("What is the string that we are searching for?")
i = 0
Do Until objFileSrc.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFileSrc.ReadLine
i = i + 1
Loop
if i = 0 then
wscript.quit
end if
objFileSrc.Close
For x = 0 to Ubound(arrFileLines)
objShell.Run "cscript ""C:\scripts\findtribal.vbs"" " & arrFileLines(x) & " " & daysOld & " " & SearchString
Next
Code:
on error resume next
Dim ArgObj
Set ArgObj = WScript.Arguments
Const FOR_READING = 1
Const ForReading = 1
strFolder = "\\" & ArgObj(0) & "\C$"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
Set fso2 = CreateObject("Scripting.FileSystemObject")
noofdays = ArgObj(1)
SearchString = ArgObj(2)
wscript.echo "Searching " & ArgObj(0) & " for '" & SearchString & "' within files modified " & noofdays & " days ago."
For Each objFile In colFiles
filenamepath = objFile.Path
Set ReadFile = fso2.OpenTextFile(filenamepath, ForReading, TristateFalse)
thisTXT = ReadFile.ReadAll
ValueSearch = InStr(1,thisTXT,SearchString,1)
If ValueSearch>=1 Then
wscript.echo "Found '"+ Searchstring + "' in "+ objFile.Path
Wscript.Sleep 5000
end if
Next
ShowSubFolders(objFolder)
Sub ShowSubFolders(objFolder)
on error resume next
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
If objSubFolder.Path <> strFolder & "\System Volume Information" then
Set colFiles = objSubFolder.Files
For Each objFile In colFiles
'if trim(left(objFile.datelastmodified-nofdays,10)) = trim(left(date-noofdays,10)) then
IF Date - DateValue(objFile.datelastmodified) < 15 THEN
filenamepath = objFile.Path
Set ReadFile = fso2.OpenTextFile(filenamepath, ForReading, TristateFalse)
thisTXT = ReadFile.ReadAll
ValueSearch = InStr(1,thisTXT,SearchString,1)
If ValueSearch>=1 Then
wscript.echo "Found '"+ Searchstring + "' in "+ objFile.Path
Wscript.Sleep 5000
end if
end if
Next
ShowSubFolders(objSubFolder)
end if
Next
End Sub
WScript.Echo objFile.Path
WScript.Echo objFile.Name
wscript.echo "completed"
Wscript.Sleep 999999999
Thanks for any help.