<% Option Explicit Dim SearchString Dim LenKey Dim fs Dim fd '----------- Const Catalog = "../mmt" '被搜索的目录,请使用非绝对路径 Const Head = "博雅堂网站搜索中心" '搜索引擎标题 Const KeyStart = "" '被搜索的HTM结构文件的可搜索范围的头标记(大小写无所谓) Const KeyEnd = "" '被搜索的HTM结构文件的可搜索范围的末标记(大小写无所谓) Const FolderImg = "dot.gif" '代表目录的图片路径[可以不改] Const FileImg = "dot.gif" '代表文件的图片路径[可以不改] Const FileType = "html" '文件类型,后缀名,此处默认的为搜索后缀名称为.html的文件内容 SearchString = Request("SearchString") '接收被搜索的数值[无需更改] LenKey = Len(KeyStart) 'KeyStart字符长度[无需更改] Function UnMapPath( Path ) UnMapPath = Replace(Mid(Path, Len(Server.MapPath("/")) + 1), "\", "/") End Function Function SearchFile( f, s, title ) Dim fo Dim content Dim pos1,pos2 On Error Resume Next Set fo = fs.OpenTextFile(f) content = fo.ReadAll fo.Close SearchFile = InStr(1, content, S, vbTextCompare) > 0 If SearchFile Then pos1 = InStr(1, Lcase(content), Lcase(KeyStart), vbTextCompare) pos2 = InStr(1, Lcase(content), Lcase(KeyEnd), vbTextCompare) title = "" If pos1 > 0 And pos2 > 0 Then title = Mid( content, pos1 + LenKey, pos2 - pos1 - LenKey ) End If End If If Err Then Response.Write ("") Response.Write ("Error #" & CStr(Err.Number) & "" & Err.description ) Response.Write ( f.name & "在正常运行" & VbCrlf) Response.Write ("" & VbCrlf) End If End Function Function FolderLink( fd ) Dim vPath vPath = UnMapPath( fd.Path ) FolderLink = "
搜索结果如下: " FolderLink = FolderLink & "
" End Function Function FileLink( f, title ) Dim vPath vPath = UnMapPath( f.Path ) If title = "" Then title = f.Name FileLink = "" & title & "" FileLink = "" End Function Sub SearchFolder( fd, s ) Dim found Dim pos Dim ext Dim f Dim sfd Dim Title 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) = LCase(FileType) Then If SearchFile( f, s, title ) Then If found = False Then found = True Response.Write FolderLink(fd) & "

" End If Response.Write FileLink(f, title) End If End If Next For each sfd In fd.SubFolders SearchFolder sfd, s Next End Sub %> <%=SearchString%> - <%=Head%>

" target=_self method="Get" style="margin:0;">
<% Set fs = Server.CreateObject("Scripting.FileSystemObject") Set fd = fs.GetFolder( Server.MapPath(Catalog)) If SearchString <> "" Then Response.Write "
您搜索的是:" & SearchString & "
" SearchFolder fd, SearchString End If %>