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>