循环访问子目录并将path存储在数组中

我有以下代码:

Function GetSubDir(ByVal sDir) Dim oFS As New FileSystemObject Dim oDir Set oDir = oFS.GetFolder(sDir) For Each oSub In oDir.SubFolders MsgBox oSub.Path GetSubDir oSub.Path Next oSub End Function 

我想修改它,以便每个子目录path存储到一个数组,但我不知道如何实现这个,或者如果它甚至是可能的。 任何人都可以帮忙吗?

尝试这个,在你的代码中创build一个基本的数组,并使其为每个子目录,如下所示…

 dim myArray() dim iCount as integer iCount=1 Set oDir = oFS.GetFolder(sDir) ' in your loop through the sub-directories... For Each oSub In oDir.SubFolders Redim Preserve myArray(iCount) myArray(iCount) = oSub.path iCount=iCount+1 Next 

心连心

菲利普

PS。 我也推荐其他人提出的文章…

如果你可以自己钓鱼,而不是向你抛出一条鱼,总是会变得更好:)