📄 search.asp.txt
字号:
<HTML>
<HEAD>
<TITLE>'<%=Request("SearchText")%>'的搜索结果</TITLE>
</HEAD>
<BODY>
<B>'<%=Request("SearchText")%>'的搜索结果</B><BR>
<%
'定义变量
Dim objFile, objFolder, objSubFolder, objTextStream
Dim bolFileFound
Dim strCount, strExt, strFile, strContent, strRoot, strText, strTitle
Dim strFilePath, strContentLen
'初始化变量
'预备搜索的文件类型为网页类型
strFile = ".asp .htm .html .js .txt .css"
'预备开始搜索的路径起点
strRoot = "/"
'获取搜索关键字
strText = Request("SearchText")
'初始化文件被找到标志为“假”
bolFileFound = False
'创建文件系统对象实例
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'获取网站在本机上的真实路径
RealPath=Server.MapPath(strRoot)
'获取网站名
VirtualPath="http://" & Request.ServerVariables("SERVER_NAME")
'创建网站根目录的文件夹列表
Set objFolder = objFSO.GetFolder(RealPath)
'调用子程序subSearch()查找并显示根文件夹中含有关键字的文件
schSubFol(objFolder)
'对网站根目录的所有一级子目录的文件进行搜索
For Each objSubFolder in objFolder.SubFolders
schSubFol(objSubFolder)
Next
'bolFileFound标志为假,显示“没有匹配结果”
If Not bolFileFound then Response.Write "没有匹配结果"
'bolFileFound标志为真,显示“搜索结束”
If bolFileFound then Response.Write "<B>搜索结束</B>"
'释放变量所占用的内存空间
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</BODY>
</HTML>
<%
'查找并显示objForder对象中文件列表中含关键字的文件的子过程
Sub schSubFol(objFolder)
On Error Resume Next
'遍历objForlder中所有文件
For Each objFile In objFolder.Files
'测试关键字是否为空,为空则直接返回
If strText = "" Then Exit Sub
'测试客户端程序是否还与服务器相连,如断开,则返回
If Not Response.IsClientConnected Then Exit sub
If Mid(objFile.Name, Len(objFile.Name) - 1, 1) = "." Then
strExt = Mid(objFile.Name, Len(objFile.Name) - 1, 2)
ElseIf Mid(objFile.Name, Len(objFile.Name) - 2, 1) = "." Then
strExt = Mid(objFile.Name, Len(objFile.Name) - 2, 3)
ElseIf Mid(objFile.Name, Len(objFile.Name) - 3, 1) = "." Then
strExt = Mid(objFile.Name, Len(objFile.Name) - 3, 4)
ElseIf Mid(objFile.Name, Len(objFile.Name) - 4, 1) = "." Then
strExt = Mid(objFile.Name, Len(objFile.Name) - 4, 5)
Else
strExt = "%$%$"
End If
If Instr(1, strFile, strExt, 1) = 0 Then Exit Sub
'创建流文件对象,按文本、只读(1)模式打开文件
Set objTextStream = objFSO.OpenTextFile(objFile.Path, 1)
'文件所有内容赋于字符串变量strContent
strContent = objTextStream.ReadAll
'从第一个字符开始查找关键字,如无,则返回;找到,则显示文件信息
position1 = InStr(1, strContent, strText, 1)
If position1 = 0 Then Exit sub
'从第一个字符开始查找网页标题,如无,则网页标题为“未命名”;找到,则为其标题
position2 = InStr(1, strContent, "<TITLE>",1)
position3 = InStr(1, strContent, "</TITLE>",1)
If position2 = 0 and position3 = 0 Then
strTitle = "未命名"
Else
strTitle = Mid(strContent, position2 + 7, position3 - position2 - 7)
End If
'获取文件物理路径
strFilePath = objFile.Path
'用网络路径名替换文件的物理路径名
strFilePath = Replace(strFilePath, RealPath, VirtualPath, 1, -1, 1)
'将物理路径中目录的分隔符“\”替换成网络路径中使用的“/”
strFilePath = Replace(strFilePath, "\", "/")
'将找到文件的计数器值加1,从1开始显示找到的文件数
strCount = strCount + 1
'显示文件内容、网络路径、上次修改时间、文件大小等信息
Response.Write "<DL><DT><B><I>"& strCount &"</I></B> - <A HREF=" &_
strFilePath & ">" & strTitle & "</A></DT><BR><DD>"
'判断从找到关键字的位置到文件最后的长度,如小于200字节,
'则全部输入;否则只输出200字节
strContentLen = Len(strContent) - position1
If strContentLen > 200 Then
strContent = Mid(strContent, position1, 200)
Else
strContent = Mid(strContent, position1, strContentLen)
End If
'为了将文件在浏览器中输出,将HTML语言的
'元素定界符“<”和“>”替换为“<”和“>”
strContent = Replace(strContent,"<","<")
strContent = Replace(strContent, ">", ">")
strText = Replace(strText,"<","<")
strText = Replace(strText, ">", ">")
strContent = Replace(strContent, strText, "<FONT color=red>"&_
strText&"</FONT>", 1, -1, 1)&"..."
Response.Write strContent
Response.Write "<BR><B><FONT size=2>URL: " & strFilePath
Response.Write "<BR>文件大小:" & FormatNumber(objFile.Size / 1024)
Response.Write "<BR>上次修改时间: " & objFile.DateLastModified
Response.Write "Kbytes</FONT></B></DD></DL>"
'设找到符合条件的文件标志为“真”
bolFileFound = True
'关闭流文件,释放内存
objTextStream.Close
Next
End Sub
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -