如何遍历某一文件夹下的所有子目录(包含多层目录)

解决方案 »

  1.   

    '引用Microsoft Scripting Runtime
    Private Sub Command1_Click()
        Dim pFolder As String, fso As New FileSystemObject
        pFolder = "D:\12"
        
        Dim objFile, objFolder    Set objFolder = fso.getFolder(pFolder)
        For Each objFile In objFolder.Files
            Debug.Print objFile.Path
        Next
        For Each objFolder In objFolder.SubFolders
            Debug.Print objFolder
        Next
    End Sub
      

  2.   

    Private Sub Command1_Click()
        MyProc1 "d:\"
    End SubSub MyProc1(ByVal Folder As String)
        Dim fso As New FileSystemObject
        Dim objFile, objFolder
        
        Set objFolder = fso.getFolder(Folder)
        For Each objFile In objFolder.Files
            MyProc2 objFile.Path
        Next
        For Each objFolder In objFolder.SubFolders
            MyProc1 objFolder '递归遍历整颗树
        Next
    End SubSub MyProc2(FileName As String)
        Debug.Print FileName
    End Sub