VBA-批量提取指定文件夹中的文件名_henry_dx_新浪博客

Sub 提取指定文件夹内的所有文件名() '含所有子文件夹内的文件
    Dim Fso As Object, arrf$(), mf&
    Set Fso = CreateObject("Scripting.FileSystemObject")
    Call GetFiles(CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件夹", 0, "").Self.Path, Fso, arrf, mf)
    [b1].Resize(mf) = Application.Transpose(arrf)
    Set Fso = Nothing
End Sub

Private Sub GetFiles(ByVal sPath$, ByRef Fso As Object, ByRef arrf$(), ByRef mf&)
    Dim Folder As Object
    Dim SubFolder As Object
    Dim File As Object
    Set Folder = Fso.GetFolder(sPath)
    
    For Each File In Folder.Files
        mf = mf + 1
        ReDim Preserve arrf(1 To mf)
        arrf(mf) = File.Name
    Next
    For Each SubFolder In Folder.SubFolders
        Call GetFiles(SubFolder.Path, Fso, arrf, mf)
    Next
    Set Folder = Nothing
    Set File = Nothing
End Sub

你可能感兴趣的:(git,shell,zip,opencv,python)