一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp 搜索文件或文件夹

时间:2008-12-18 编辑:简简单单 来源:一聚教程网

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

html页面.





Search term or phrase    

 

和您将需要建立一个档案,内容表中的波纹命名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 ("

Search results

")
 

   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,"")>0 then
                  longitud=instr(ct,"")
                  longitud=longitud -1
                          ct=left(ct,longitud)
                          longitud2=len(ct)
                  longitud=instr(ct,"") <br />                   longitud=longitud2 -longitud -6 <br />                           ct=right(ct,longitud) <br />                      else <br />                         if instr(ct,"")>0 then
                    longitud=instr(ct,"")
                    longitud=longitud -1
                            ct=left(ct,longitud)
                            longitud2=len(ct)
                    longitud=instr(ct,"") <br />                     longitud=longitud2 -longitud -6 <br />                             ct=right(ct,longitud) <br />              end if <br />                      end if</p> <p>                    SearchResponse= SearchResponse +"<TR><TD>"+ ct + "</TD><TD ALIGN=CENTER VALIGN=MIDDLE>" + " <A HREF=" + "/" + FolderName + "/" + Wfile +"> More </A></TD></TR>" <br />           longitud=0 <br />                   ct=""</p> <p>                  end if <br />           end if</p> <p>Next</p> <p>Response.Write ("<HTML><HEAD><TITLE>Search results

") 

Response.Write ("

Search Results
") 

Response.Write ("

") 
if SearchResponse<>"" then 
Response.Write SearchResponse
else
Response.Write ("")
end if
Response.Write ("
The specified term or phrase was not found
")

Response.Write ("

")

End Sub
%>

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

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

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

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

热门栏目