|
FSO递归简直神了, 太好用了, 感谢群子的无私分享. 下面是改成输出成两个数组, 分别是文件夹完整路径和文件完整路径的.- Private folders(), files(), n%, k%
- Sub getAll()
- Dim path$, sh, f
- On Error Resume Next
- n = 0
- k = 0
- Erase folders, files
- Set sh = CreateObject("Shell.Application")
- Set f = sh.BrowseForFolder(0, "请选择文件夹", 0, 0)
- path = f.self.path
- If path = "" Then Exit Sub
- If Right(path, 1) <> "" Then path = path & ""
- ListAllFso path
- If n > 0 Then Sheet1.[a1].Resize(n) = Application.Transpose(folders)
- If k > 0 Then Sheet1.[b1].Resize(k) = Application.Transpose(files)
- End Sub
- Function ListAllFso(myPath$)
- Set fld = CreateObject("Scripting.FileSystemObject").GetFolder(myPath)
- For Each f In fld.files
- k = k + 1
- ReDim Preserve files(1 To k)
- files(k) = myPath & f.Name
- Next
- For Each fd In fld.SubFolders
- n = n + 1
- ReDim Preserve folders(1 To n)
- folders(n) = myPath & fd.Name
- Call ListAllFso(fd.path & "")
- Next
- End Function
复制代码
|
|