FSO 遍历文件夹和文件

来源:互联网 发布:excel 数据左上角 编辑:程序博客网 时间:2024/04/30 07:00

Attribute VB_Name = "遍历文件夹和文件"
Option Explicit

Public Sub 遍历文件夹和文件(sFolder As String)
    Dim fs As Object
    On Error Resume Next
    Set fs = CreateObject("Scripting.FileSystemObject")
    File_Folder_List (fs.GetFolder(sFolder))
    Set fs = Nothing
End Sub

Private Sub File_Folder_List(df As Object)

'循环处理文件集合

    Dim objFile As Object, objSubFolder As Object

    '文件集合
    For Each objFile In df.Files
        '
        '
        '文件处理过程
        '
        '
    Next objFile

    Set objFile = Nothing

    '文件夹集合
    For Each objSubFolder In df.SubFolders
       
        '
        '
        '文件夹处理过程
        '
        '
       
        File_Folder_List objSubFolder   '递归循环处理文件夹
       
    Next objSubFolder

    Set objSubFolder = Nothing
End Sub

原创粉丝点击