Algorithm and application direction of ASP retrieving Web site-specific directory files
Source: Internet
Author: User
There is a problem with many of our web sites, is the link maintenance update, this is a very heavy work, if not the dedicated staff to maintain the large web site, the normal site of the site update maintenance work has become a very troubling problem, especially in the absence of a lot of manpower, It is more annoying to maintain updated links frequently, because the job is not creative, it's time-consuming, and Jack is obviously not the kind of person who likes to spend a lot of time on something that's not creative, and yes, Jack came up with an ASP's program prototype, let it do the work we hate!
Now let's assume that you have such a website maintenance task, is to link each month's economic commentary in a compartmentalized way for everyone to look at, which covers all aspects of the economy, may have a GDP, a price index, an industrial development, and they have a common character, Is their file name represents the content of their comments, for example: "XX City 1999 gross domestic product completion analysis", under so many appropriate assumptions (giggle, assume almost more than Samuelson's economics!) We have a chance to steal it! All we have to do is copy these files into the comments directory subdirectory, and then write an ASP page, the function of which is to retrieve the files under the specified directory, and retrieve the results to make a clickable link, so how should we write?
Very simple, we simply let the ASP give the specified directory of the file name set, and traverse the collection, the collection of each element into the corresponding links for everyone to choose the line! Also, to query all the economic categories for all file names that contain a feature string? Little Case! All you have to do is put the function of retrieving the file into a recursive directory retrieval function. (Hey, don't tell me you're not going to pass it on!) )
In this way, we can also write a song system (hee, I like to listen to MP3) the singer into the directory name, the song plus Chinese name, all OK! Want to hear A "Love" song? Ok! Enter the Love word! You can find all the songs you love! (Say: Love you love into the bone!) Hey, chop Band! Jack the lead singer! )
In addition, you add the extension code (delete the specified file code), if with upload ASP code, you can even write a remote Web maintenance system! Of course, this kind of thing is not done by Jack! ASP is not perfect, the binary file read and write can not do! So you can only manipulate text files, Hee, the dream is gone? It doesn't matter, use VC! Write ISAPI can do it!
The following code, due to the integrity of the comments (Jack did not surf the internet in the afternoon to write it!) Hey, I do not know how many mm in the chat waiting for my heartache! , I will not say more, please analyze your own!
<%
' Get the string to be included in the name of the file you want to query from the form variable set
Data=request.form ("Search_data")
' Call function query all subdirectories (all subtrees) under the target query directory
' Function call rule: Search_folder (the string to query, the virtual absolute path of the query target, the true absolute path of the query target)
P=search_folder (data, "Http://jack/cgi-bin", "C:\webshare\wwwroot\cgi-bin")
%>
<script language= "VBScript" runat=server>
' Directory retrieval function
function Search_folder (Search_data,v_path,c_path)
Dim file_system,cur_folder,sub_folders,sub_files
' Determines whether the query string is valid or not NULL
If not IsEmpty (Search_data) and Len (search_data) >0 Then
' Set up file system objects
Set File_system=createobject ("Scripting.FileSystemObject")
' Set up the current directory object
Set Cur_folder=file_system.getfolder (C_path)
' Create a collection of subdirectory objects for the current directory
Set Sub_folders=cur_folder.subfolders
' Traversal of subdirectories collection
For each each_sub_folder in Sub_folders
' Determines that the attributes of subdirectories are normal subdirectories
If Each_sub_folder.attributes=16 Then
' Get the current sub virtual absolute path and true absolute path
' NOTE: The default subdirectory for this program is the same level as the child virtual directory and the name is the same.
sub_v_path=v_path& "/" &each_sub_folder.name
sub_c_path=c_path& "" &each_sub_folder.name
' Call the file retrieval function to retrieve the string matching files under the current subdirectory
P=search_file (Search_data,sub_v_path,sub_c_path)
' recursively retrieves the next level of directory for the current subdirectory
P=search_folder (Search_data,sub_v_path,sub_c_path)
End If
Next
' Clears all server-side objects
Set each_sub_folder=nothing
Set sub_folders=nothing
Set cur_folder=nothing
Set file_system=nothing
End If
End Function
'********************************
' File matching retrieval function '
function Search_file (Search_data,v_path,c_path)
Dim File_system,sub_files,sub_file_v_path,sub_out_v_path
' Verify that the path is not empty
If not IsEmpty (C_path) Then
Set File_system=createobject ("Scripting.FileSystemObject")
Set Cur_folder=file_system.getfolder (C_path)
' Set up a collection of file objects under the Retrieve directory
Set Sub_files=cur_folder.files
' Traverse the collection of file objects
For each each_file in Sub_files
' Match string and filename
If InStr (Each_file.name,search_data) <>0 Then
' Create available links, output matching files
sub_file_v_path=v_path& "/" &each_file.name
' Replace the possible spaces in the path and file name so the Web can correctly determine the path
Sub_out_v_path=replace (Sub_file_v_path, "", "%20")
Response.Write ("<p><a 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>
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