SoFunction
Updated on 2025-04-13

Text Search

<%
Head = "Search"
SearchString = Request("SearchString")
count=0

'Convert the actual path of the current directory to a virtual path
Function UnMapPath( Path )
UnMapPath = Replace(Mid(Path, Len(("/")) + 1), "\", "/")
End Function


Function SearchFile( f, s, title )
Set fo = (f)
content = 'Read all text to content

SearchFile = InStr(1, content, S, vbTextCompare) > 0 'Start from the first character to check whether there is S in the content
If SearchFile Then'If there is, file TITLE deposit variable
pos1 = InStr(1, content, "<TITLE>", vbTextCompare)
pos2 = InStr(1, content, "</TITLE>", vbTextCompare)
title = ""
If pos1 > 0 And pos2 > 0 Then'Take the character in the middle of the TITLE tag
title = Mid( content, pos1 + 7, pos2 - pos1 - 7 )
End If
End If
End Function

Function FileLink( f, title )
vPath = UnMapPath( )' take the path
If title = "" Then title = 'Make a link
FileLink = "<A HREF=""" & vPath & """>" & title & "</A>"
FileLink = "<UL>·" & FileLink & "</UL>"
End Function

Sub SearchFolder( fd, s )
found = False
For each f In
pos = InStrRev(, "." )
If pos > 0 Then
ext = Mid(, pos + 1 )
Else
ext = ""
End If
If LCase(ext) = "htm" Then' displays the file with the extension name HTM
If SearchFile( f, s, title ) Then
FileLink(f, title)
count=count+1
' cstr(count)
End If
End If
Next

For each sfd In
SearchFolder sfd, s
Next
End Sub
%>
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title><%=Head%></title>
</head>

<body bgcolor="#FFFFFF">

<h1><%=Head%></h1>

<hr>

<form action="" method="Get">
<p>Please enter the content you want to search for: <input type="text"
size="20" name="SearchString" value="<%=SearchString%>"> <input
type="submit" value="Search"> </p>
</form>
<%
Set fs = ("")
Set fd = ( ("/") ) 'Set the path to start the search!

If SearchString <> "" Then
"<H2>Search<font color=red>" & SearchString & "</font>The results are as follows:</H2><P>"
SearchFolder fd,SearchString
End If
%>
<hr>
</body>
</html>