asp经典搜索引擎

时间:2011-12-09 11:39:45

标签: asp-classic search-engine

我已经尝试过如下搜索引擎脚本:

<HTML><BODY>
<B>Search Results for <%=Request("SearchText")%></B><BR>

<%
Const fsoForReading = 1

Dim strSearchText
strSearchText = Request("SearchText")

''# Now, we want to search all of the files
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")


Dim objFolder
Set objFolder = objFSO.GetFolder(Server.MapPath("/"))

Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False

For Each objFile in objFolder.Files
  If Response.IsClientConnected then
    Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)

    strFileContents = objTextStream.ReadAll

    If InStr(1,strFileContents,strSearchText,1) then
       Response.Write "<LI><A HREF=""/" & objFile.Name & _
                      """>" & objFile.Name & "</A><BR>"

       bolFileFound = True
    End If

    objTextStream.Close
  End If
Next

if Not bolFileFound then Response.Write "No matches found..."

Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</BODY></HTML>

输出将只显示文件名,我想要的是文件的标题。 我的问题是,如何获取字符串以显示结果?或者在asp经典中是否还有与搜索引擎相关的其他脚本?

1 个答案:

答案 0 :(得分:0)

我不确定我的意思是什么,但是如果你打算在没有路径或扩展名的情况下抓取文件名,这里是我使用的代码片段:

Public Function GetFileName(flname As String) As String
'From: http://www.freevbcode.com/ShowCode.asp?ID=1638
'By:   Maria Rapini

    'Get the filename without the path or extension.
    'Input Values:
    '   flname - path and filename of file.
    'Return Value:
    '   GetFileName - name of file without the extension.

    Dim posn As Integer, i As Integer
    Dim fName As String

    posn = 0
    'find the position of the last "\" character in filename
    For i = 1 To Len(flname)
        If (Mid(flname, i, 1) = "\") Then posn = i
    Next i

    'get filename without path
    fName = Right(flname, Len(flname) - posn)

    'get filename without extension
    posn = InStr(fName, ".")
        If posn <> 0 Then
            fName = Left(fName, posn - 1)
        End If
    GetFileName = fName
End Function