Read all file code under the folder in ASP

Source: Internet
Author: User
The code is as follows Copy Code

<%
' 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
Sub_folder_name=each_sub_folder.name ' Directory name
sub_folder_path=c_path& "" &each_sub_folder.name
Set Cur_sub_folder=file_system.getfolder (Sub_folder_path)
' Set up a collection of file objects under the Retrieve directory
Set Sub_files=cur_sub_folder.files
' Traverse the collection of file objects
For each each_file in Sub_files
Name=each_file.name ' fetch filename
Next

Next


*********************************************************************************************************


Using recursion

Set File_system=createobject ("Scripting.FileSystemObject")

Sub GetFile (C_path)
Set Cur_folder=file_system.getfolder (C_path)
Set Sub_folders=cur_folder.subfolders

For each each_sub_folder in Sub_folders
Set Sub_files=cur_sub_folder.files
For each each_file in Sub_files
Name=each_file.name ' fetch filename
Next
Sub_folder_name=each_sub_folder.name ' Directory name
sub_folder_path=c_path& "" &each_sub_folder.name
Sub GetFile (Sub_folder_path)
Next

End Sub


********************************************************************************


function Search_folder (c_path) ' Directory retrieval functions
' 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
' Search for files in the current directory
P=search_file (C_path)
' Traversal of subdirectories collection
For each each_sub_folder in Sub_folders
' Determines that the attributes of subdirectories are normal subdirectories
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 (Sub_c_path)
' recursively retrieves the next level of directory for the current subdirectory
P=search_folder (Sub_c_path)
Next
' Clears all server-side objects
Set sub_files=nothing
Set each_sub_folder=nothing
Set sub_folders=nothing
Set cur_folder=nothing
Set file_system=nothing
End If
End Function


**********************************************


Set File_system=createobject ("Scripting.FileSystemObject")
Set Cur_folder=file_system.getfolder (C_path
' Establish a collection of file objects in the retrieved directory
set sub_files=cur_folder.files
' traverse the collection of file objects
for each each_file in Sub_files
Name=e Ach_file.name ' fetch filename
next 
%>

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.