How to perform a text search?

Source: Internet
Author: User

<%
Head = "Search"
SearchString = Request ("SearchString ")
Count = 0

Function UnMapPath (Path)
UnMapPath = Replace (Mid (Path, Len (Server. MapPath ("/") + 1 ),"\","/")

'Convert the actual path of the current directory to a virtual path.
End Function

Function SearchFile (f, s, title)
Set fo = fs. OpenTextFile (f)
Content = fo. ReadAll

'Read all the text to the content.
Fo. Close
SearchFile = InStr (1, content, S, vbTextCompare)> 0

'Check whether there is S in the content from the first character.
If SearchFile Then

'If there is, the title of the file is put into the variable.
Pos1 = InStr (1, content, "<title>", vbTextCompare)
Pos2 = InStr (1, content, "</title>", vbTextCompare)
Title = ""
If pos1> 0 And pos2> 0 Then

'Use the title to mark the characters in the middle.
Title = Mid (content, pos1 + 7, pos2-pos1-7)
End If
End If
End Function

Function FileLink (f, title)
VPath = UnMapPath (f. Path)

'Obtain the path.
If title = "" Then title = f. Name

'Make a link.
FileLink = "<a href =" "& vPath &" ">" & title & "</A>"
FileLink = "<UL> ·" & FileLink & "</UL>"
End Function

Sub SearchFolder (fd, s)
Found = False
For each f In fd. Files
Pos = Limit Rev (f. Path ,".")
If pos> 0 Then
Ext = Mid (f. Path, pos + 1)
Else
Ext = ""
End If
If LCase (ext) = "htm" Then

'Display the file with the extension name HTM.
If SearchFile (f, s, title) Then
Response. Write FileLink (f, title)
Count = count + 1
Response. Write cstr (count)
End If
End If
Next

For each sfd In fd. SubFolders
SearchFolder sfd, s
Next
End Sub
%>
<Html>

<Head>
<Meta http-equiv = "Content-Type"
Content = "text/html; charsets = gb_2312-80">
<Meta name = "GENERATOR" content = "Microsoft FrontPage Express 2.0">
<Title> <% = head %> </title>
</Head>

<Body>

<H1> galaxy movie invincible text search <% = head %>

<Hr>

<Form action = "search. asp" method = "Get">
<P> enter the content you want to search for: <input type = "text"
Size = "20" name = "SearchString" value = "<% = SearchString %>"> <input
Type = "submit" value = "Search"> </p>
</Form>
<%
Set fs = Server. CreateObject ("Scripting. FileSystemObject ")
Set fd = fs. GetFolder (Server. MapPath ("/"))

'Set the start search path.

If SearchString <> "" Then
Response. Write "<H2> Search <font color = red>" & SearchString & "</font> result: </H2> <P>"
SearchFolder fd, SearchString
End If
%>
<Hr>
</Body>

[1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.