zl程序教程

您现在的位置是:首页 >  其他

当前栏目

文本搜索

搜索 文本
2023-06-13 09:13:46 时间
<%
Head="搜索"
SearchString=Request("SearchString")
count=0

"把当前目录的实际路径转换为虚拟路径
FunctionUnMapPath(Path)
UnMapPath=Replace(Mid(Path,Len(Server.MapPath("/"))+1),"\","/")
EndFunction


FunctionSearchFile(f,s,title)
Setfo=fs.OpenTextFile(f)
content=fo.ReadAll"读全部文本到content
fo.Close
SearchFile=InStr(1,content,S,vbTextCompare)>0"从第一个字符开始检查content里面是否有S
IfSearchFileThen"如果有,则提出文件TITLE存入变量
pos1=InStr(1,content,"<TITLE>",vbTextCompare)
pos2=InStr(1,content,"</TITLE>",vbTextCompare)
title=""
Ifpos1>0Andpos2>0Then"取TITLE标记中间的字符
title=Mid(content,pos1+7,pos2-pos1-7)
EndIf
EndIf
EndFunction

FunctionFileLink(f,title)
vPath=UnMapPath(f.Path)"取路径
Iftitle=""Thentitle=f.Name"做链接
FileLink="<AHREF="""&vPath&""">"&title&"</A>"
FileLink="<UL>·"&FileLink&"</UL>"
EndFunction

SubSearchFolder(fd,s)
found=False
ForeachfInfd.Files
pos=InStrRev(f.Path,".")
Ifpos>0Then
ext=Mid(f.Path,pos+1)
Else
ext=""
EndIf
IfLCase(ext)="htm"Then"显示扩展名字为HTM的文件
IfSearchFile(f,s,title)Then
Response.WriteFileLink(f,title)
count=count+1
"Response.Writecstr(count)
EndIf
EndIf
Next

ForeachsfdInfd.SubFolders
SearchFoldersfd,s
Next
EndSub
%>
<html>

<head>
<metahttp-equiv="Content-Type"
content="text/html;charset=gb_2312-80">
<metaname="GENERATOR"content="MicrosoftFrontPageExpress2.0">
<title><%=Head%></title>
</head>

<bodybgcolor="#FFFFFF">

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

<hr>

<formaction="search.asp"method="Get">
<p>请输入欲搜索的内容:<inputtype="text"
size="20"name="SearchString"value="<%=SearchString%>"><input
type="submit"value="搜索"></p>
</form>
<%
Setfs=Server.CreateObject("Scripting.FileSystemObject")
Setfd=fs.GetFolder(Server.MapPath("/"))"设置开始搜索的路径!

IfSearchString<>""Then
Response.Write"<H2>搜索<fontcolor=red>"&SearchString&"</font>结果如下:</H2><P>"
SearchFolderfd,SearchString
EndIf
%>
<hr>
</body>
</html>