天涯之外

导航

asp 搜索文件或文件夹

此搜索工具可以让您将搜寻字词或词组在您的网站,以及由此产生的网页将显示您的访客网页的标题和一个指向它的链接。
你只需要包括波纹管的形式在您的网页:

html页面.

<form method="POST" action="/cgi-bin/searchfiles.asp">
<table border=0 cellpadding=5 bgcolor=AAAAAA><tr>
<td align=center>
Search term or phrase &nbsp; <input type=text name=term size=15> &nbsp; <input type=submit value="search"></td>
</tr></table>
</form> 

和您将需要建立一个档案,内容表中的波纹命名searchfiles.asp在相应的目录。 Active Server Pages中必须具备的服务器。指示都在底部。

<%
SearchTerm = request.form("term")

Novalid=" a b c d e f g h i j k l m n o p q r s t u v w x y z yes no and more"
NovalidResponse ="Go back and try again. Your search term is very common"
 

if instr(SearchTerm,Novalid)=0 then

Response. Write ("<CENTER><H2>Search results</H2></CENTER>")
 

   FolderName= "FolderName"
   ShowList()

else
Response.Write NovalidResponse
End if

SearchResponse=""
%>

<%
Sub ShowList()
FolderToCheck = server.mappath("") &"/" & FolderName & "/"
 Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(FolderToCheck)
 Set fc = f.Files
 For Each f1 in fc

         Wfile = f1.name
          if right(Wfile, 5)=".html" OR right(Wfile, 4)=".htm" then
            Wfile2 = FolderToCheck & Wfile
            Set fs = CreateObject("Scripting.FileSystemObject")
            Set a = fs.OpenTextFile(Wfile2)
            ct = a.ReadAll
            a.close
            ct2=lcase(ct)
            SearchTerm2 = lcase(SearchTerm)

                  if instr(ct2,SearchTerm2)>0 then

                      if instr(ct,"</title>")>0 then
                  longitud=instr(ct,"</title>")
                  longitud=longitud -1
                          ct=left(ct,longitud)
                          longitud2=len(ct)
                  longitud=instr(ct,"<title>")
                  longitud=longitud2 -longitud -6
                          ct=right(ct,longitud)
                     else
                        if instr(ct,"</TITLE>")>0 then
                    longitud=instr(ct,"</TITLE>")
                    longitud=longitud -1
                            ct=left(ct,longitud)
                            longitud2=len(ct)
                    longitud=instr(ct,"<TITLE>")
                    longitud=longitud2 -longitud -6
                            ct=right(ct,longitud)
             end if
                     end if

                    SearchResponse= SearchResponse +"<TR><TD>"+ ct + "</TD><TD ALIGN=CENTER VALIGN=MIDDLE>" + " <A HREF=" + "/" + FolderName + "/" + Wfile +"> More </A></TD></TR>"
          longitud=0
                  ct=""

                  end if
          end if

Next

Response.Write ("<HTML><HEAD><TITLE>Search results</TITLE></HEAD><BODY BGCOLOR=FFFFFF><CENTER>") 

Response.Write ("<TABLE BORDER=0 WIDTH=550><TR><TD BGCOLOR=C0C0C0><FONT SIZE=5><B>Search Results</B></FONT></TD></TR></TABLE>") 

Response.Write ("<TABLE BORDER=0 WIDTH=550>") 
if SearchResponse<>"" then 
Response.Write SearchResponse
else
Response.Write ("<TR><TD>The specified term or phrase was not found</TD></TR>")
end if
Response.Write ("</TABLE>")

Response.Write ("</CENTER></BODY></HTML>")

End Sub
%>

您可能含有你不想被搜查的变量“ Novalid ” 。如果在任期列入“ Novalid ”的要求,撰写您的反应变量“ NovalidResponse ” 。

“搜索结果”的文本将显示在上方的搜索结果页。

“文件夹”是您想要的目录搜索。只有“ 。热媒”和“ 。的HTML ”的文件在此目录将搜查。子目录不要搜索。如果你想要搜寻您的顶级目录,设置文件夹= “ ” 。此脚本只是在最有用的目录只。我不建议检查50多个文件(尝试友好与您的服务器! )

此脚本将显示为响应标题清单的网页所要求的任期词组。

posted on 2009-11-12 17:18  天涯之外  阅读(727)  评论(0编辑  收藏  举报