<%
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(Server.MapPath(/)) + 1), /, /)
End Function
Function SearchFile( f, s, title )
Set fo = fs.OpenTextFile(f)
content = fo.ReadAll' read all text to content
fo.Close
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( f.Path )' take the path
If title = Then title = f.Name' to make links
FileLink = <A HREF= & vPath & > & title & </A>
FileLink = <UL>· & FileLink & </UL>
End Function
Sub SearchFolder( fd, s )
found = False
For each f In fd.Files
pos = InStrRev(f.Path, . )
If pos > 0 Then
ext = Mid(f.Path, pos + 1 )
Else
ext =
End If
If LCase(ext) = htm Then'Show file with extension name HTM
If SearchFile( f, s, title ) Then
Response.Write FileLink(f, title)
count=count+1
' Response.Write cstr(count)
End If
End If
Next
For each sfd In fd.SubFolders
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=search.asp 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 = Server.CreateObject(Scripting.FileSystemObject)
Set fd = fs.GetFolder( Server.MapPath(/) ) 'Set the path to start the search!
If SearchString <> Then
Response.Write <H2>Search<font color=red> & SearchString & </font>The results are as follows:</H2><P>
SearchFolder fd, SearchString
End If
%>
<hr>