×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

this one?

Function FolderSet(FolPath)
' finds all folders in path FolPath
' WARNING - UNCOMMENT NEXT TWO LINES IF
' FSO NOT DECLARED IN MAIN BODY
' Dim FSO
' Set FSO = CreateObject("Scripting.FileSystemObject")
Dim Fol, strTemp, aFols(), oFolder, subFolder, aTmp, i
ReDim aFols(-1)
Set oFolder = FSO.GetFolder(FolPath)
For Each Fol In oFolder.SubFolders
ReDim Preserve aFols(UBound(aFols) + 1)
aFols(UBound(aFols)) = Fol.Path
Next
'Recurse through all of the folders
For Each subFolder In oFolder.subFolders
aTmp = FolderSet(subFolder)
For i = 0 To UBound(aTmp)
ReDim Preserve aFols(UBound(aFols) + 1)
aFols(UBound(aFols)) = aTmp(i)
i = i + 1
Next
Next
FolderSet = aFols
End Function
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 单纯使用vbs里面的filesystemobject可不可以列出一个drive下面的所有folder? drive好像不支持subfolders这个集合。
    • this one?
      Function FolderSet(FolPath)
      ' finds all folders in path FolPath
      ' WARNING - UNCOMMENT NEXT TWO LINES IF
      ' FSO NOT DECLARED IN MAIN BODY
      ' Dim FSO
      ' Set FSO = CreateObject("Scripting.FileSystemObject")
      Dim Fol, strTemp, aFols(), oFolder, subFolder, aTmp, i
      ReDim aFols(-1)
      Set oFolder = FSO.GetFolder(FolPath)
      For Each Fol In oFolder.SubFolders
      ReDim Preserve aFols(UBound(aFols) + 1)
      aFols(UBound(aFols)) = Fol.Path
      Next
      'Recurse through all of the folders
      For Each subFolder In oFolder.subFolders
      aTmp = FolderSet(subFolder)
      For i = 0 To UBound(aTmp)
      ReDim Preserve aFols(UBound(aFols) + 1)
      aFols(UBound(aFols)) = aTmp(i)
      i = i + 1
      Next
      Next
      FolderSet = aFols
      End Function