Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15549

Little Help

$
0
0
Hello All,

I'm not a programmer, I'm an IT professional who uses scripting occasionally to make my life easier. So I apologize for my naivety. I have been tasked with a fairly simple work project that requires a simple search so that employees can quickly find resources on an intranet IIS website I created. The route has led me to a script (which I did not create but have modified) that I've had good results with but have hit a snag. I use a search box that searches a folder and all it's subfolders which contain an index.html file. In each index.html file, I've added a comment section that begins with <!KeywordsStart and ends with KeywordsBegin>. In between those strings will be key words that reference that webpage. I can search the content of the index.html files without the regex section and return results with no problem. The problem I'm having is not being able to match/compare the text between those two strings using the regex section and then match/compare it with the original search request variable. It's still returning all search request matches contained in the index.html file. I need to keep the search limited to only text between those strings. Thank you in advance and here's the script (the hyperlink line is just a test at the moment):

Dim strtextToSearch
strtextToSearch = Request("TextToSearch")

Dim fso

Const ForReading = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")

Dim FolderToSearch
FolderToSearch = "C:\inetpub\CallCenterResources\Resources"


Dim objFolder
Set objFolder = fso.GetFolder(FolderToSearch)

Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False

Dim FilesCounter
FilesCounter = 0 'Total files found

ShowSubfolders fso.GetFolder(FolderToSearch)
Sub ShowSubFolders(Folder)

For Each subFolder in Folder.subFolders
Set objFolder = fso.GetFolder(subFolder.Path)
Set objFiles = objFolder.Files

For Each objFile in objFiles
Set objRegExp = New RegExp 'Set our pattern
objRegExp.Pattern = "\bKeywordsStart\s+([\s\S]*?)\s+\KeywordsEnd\b"
objRegExp.IgnoreCase = True
objRegExp.Global = True
Set objTextStream = fso.OpenTextFile(objFile.Path,ForReading)
strFileContents = objTextStream.ReadAll
Dim objMatches
Set objMatches = objRegExp.Execute(strFileContents)
If (InStr(1,strFileContents,strtextToSearch,1) and (objMatches.Count > 0)) then
Response.Write "<br>"
Response.Write("<a href='http://192.168.168.12:1123/Resources/Podiatry/index.html'>Podiatry</a>")
FilesCounter = FilesCounter + 1
Response.Write "<br>"
End If
objTextStream.Close

Next
Next

End Sub

if FilesCounter = 0 then
Response.Write "<br>"
Response.Write "<br>"
Response.Write "Sorry, no matches found"
else
Response.Write "<br>"
Response.Write "Total files found : " & FilesCounter
end if

Set objTextStream = Nothing
Set objFolder = Nothing

Set fso = Nothing

Viewing all articles
Browse latest Browse all 15549

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>