On Error Resume Next
'Change the next three lines'
Const FOLDER_TO_SEARCH = "S:\scrimac"
Const FILES_TO_FIND = "*.sas"
Const TEXT_TO_FIND = "s:\"
Dim objFSO, objFolder, objFile, objTextStream, objReport, objRegex, colMatches, strRoot, strExtension, varBuffer, arrFTF
Dim lngFilesChecked, lngFilesMatched, lngHits
arrFTF = Split(FILES_TO_FIND, ".")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the output file name on the next line'
Set objReport = objFSO.CreateTextFile("C:\Documents and Settings\eza9507\My Documents\FileSearch.txt")
objReport.WriteLine "Folder to Search: " & FOLDER_TO_SEARCH
objReport.WriteLine "Files to Search: " & FILES_TO_FIND
objReport.WriteLine "Text to Find: " & TEXT_TO_FIND
objReport.WriteLine ""
Set objRegex = CreateObject("VBscript.RegExp")
With objRegex
.IgnoreCase = True
.Pattern = TEXT_TO_FIND
.Global = True
End With
Set objFolder = objFSO.GetFolder(FOLDER_TO_SEARCH)
For Each objFile In objFolder.Files
strRoot = objFSO.GetBaseName(objFile.Name)
strExtension = objFSO.GetExtensionName(objFile.Name)
If (strRoot = arrFTF(0)) Or (arrFTF(0) = "*") Then
If (strExtension = arrFTF(1)) Or (arrFTF(1) = "*") Then
lngFilesChecked = lngFilesChecked + 1
Set objTextStream = objFSO.OpenTextFile(objFile.Path)
varBuffer = objTextStream.ReadAll
Set colMatches = objRegex.Execute(varBuffer)
If colMatches.count > 0 Then
lngFilesMatched = lngFilesMatched + 1
lngHits = lngHits + colMatches.count
objReport.WriteLine "File: " & objFile.Path & " Matches: " & colMatches.count
End If
objTextStream.Close
End If
End If
Next
objReport.WriteLine ""
objReport.WriteLine "Files Checked: " & lngFilesChecked
objReport.WriteLine "Files with Text: " & lngFilesMatched
objReport.WriteLine "Total Matches: " & lngHits
objReport.Close
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Set objTextStream = Nothing
Set objReport = Nothing
Set objRegex = Nothing
Set colMatches = Nothing
WScript.Echo "Search Complete"
WScript.Quit
|