Question : A SCRIPT THAT WILL SEARCH AND SHOW RESULT FOUND

Hello Friends,

I found some script that will search files in a specified directory for a certain string. The title of the solution was 'A Script that will search a text file' ID:24497423. I am getting an error on Line 30 as did the previous user so I added the 'On Error Resume Next' just like they mentioned in the log. I did get the some information that is listed below but the code did not list the file names locations for the files that it found. How can I edit this script to ouput the files?

Thanks,

Jeff

Filesearch.txt <OUTPUT>
Folder to Search: S:\scrimac
Files to Search: *.sas
Text to Find: s:\

Files Checked: 88
Files with Text: 88
Total Matches:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
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

Answer : A SCRIPT THAT WILL SEARCH AND SHOW RESULT FOUND

Random Solutions  
 
programming4us programming4us