How to Create a search result with a link?

Source: Internet
Author: User

How to Create a search result with a link?

<%
Data = request. form ("search_data ")

'SlaveFORMVariable set to get the string to be included in the name of the file to be queried
P = search_folder (data, "http: // jack/cgi-bin", "c: \ intels \ wwwroot \ cgi-bin ")

'Call the function to query all subdirectories in the target Query Directory(All subtree),Method: Search_folder (String to be queried,Query the virtual absolute path of the target,Returns the actual absolute path of the target.)

%>


<Script language = "vbscript" RUNAT = SERVER>
Function search_folder (search_data, v_path, c_path)
Dim file_system, cur_folder, sub_folders, sub_files

'Directory retrieval Function
If not isempty (search_data) and len (search_data)> 0 then

'Determines whether the query string is valid and not empty.
Set file_system = createobject ("scripting. filesystemobject ")

'Create a File System Object
Set cur_folder = file_system.getfolder (c_path)

'Create the current directory object
Set sub_folders = cur_folder.subfolders

'Create a subdirectory object set for the current directory
For each each_sub_folder in sub_folders

'Traverse sub-directory Sets
If each_sub_folder.attributes = 16 then

'Make sure that the sub-directory attributes are normal sub-directories.
Sub_v_path = v_path & "/" & each_sub_folder.name
Sub_c_path = c_path & "& each_sub_folder.name

'Obtain the current sub-virtual absolute path and actual absolute path.,The name of the default subdirectory is identical to that of the sub-virtual directory.

P = search_file (search_data, sub_v_path, sub_c_path)

'Call the file retrieval function to perform string matching search for files in the current subdirectory
P = search_folder (search_data, sub_v_path, sub_c_path)

'Recursively retrieve the next-level directory of the current subdirectory

End if
Next
Set each_sub_folder = nothing
Set sub_folders = nothing
Set cur_folder = nothing
Set file_system = nothing

'Clear

End if
End function
Slave --------------------------------------------------------------------------------------------------------------------------------

Function search_file (search_data, v_path, c_path)
Dim file_system, sub_files, sub_file_v_path, sub_out_v_path

'File matching retrieval Function
If not isempty (c_path) then

'Confirm path is not empty
Set file_system = createobject ("scripting. filesystemobject ")
Set cur_folder = file_system.getfolder (c_path)
Set sub_files = cur_folder.files

'Create a collection of file objects in the search directory
For each each_file in sub_files

'Traversing a collection of file objects
If instr (each_file.name, search_data) <> 0 then

'Match string and file name
Sub_file_v_path = v_path & "/" & each_file.name

'Create available links,Output matching File
Sub_out_v_path = Replace (sub_file_v_path, "", "% 20 ")

'Replace spaces in path and file name,So that the system can determine the path
Response. write ("<p> <
Href = "& sub_out_v_path &"> "& sub_file_v_path &" </a> ")
End if
Next
Set sub_out_v_path = nothing
Set sub_file_v_path = nothing
Set each_file = nothing
Set sub_files = nothing
Set file_system = nothing
End if
End function
</Script>

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.