|
楼主 |
发表于 2013-4-7 22:41
|
显示全部楼层
本帖最后由 小花鹿 于 2013-4-9 10:45 编辑
列出ThisWorkbook.Path及子文件夹中的文件名:
Option Explicit
Dim FileList(1 To 65536, 1 To 1), n&
Sub FolderFileList()
Dim fso, Folder, f
Set fso = CreateObject("scripting.filesystemobject")
Set Folder = fso.getfolder(ThisWorkbook.Path)
For Each f In Folder.Files
n = n + 1
FileList(n, 1) = f
Next f
SubFolderFileList (ThisWorkbook.Path)
[a1].Resize(n) = FileList
n = 0
End Sub
Function SubFolderFileList(pth)
Dim fso, Folder, SubFolder, f, fd
Set fso = CreateObject("scripting.filesystemobject")
Set Folder = fso.getfolder(pth)
Set SubFolder = Folder.subfolders
For Each fd In SubFolder
For Each f In fd.Files
n = n + 1
FileList(n, 1) = f
Next f
SubFolderFileList (fd.Path)
Next fd
End Function
补充内容 (2014-8-27 21:49):
Sub test()
Dim fso, fld, f, br(1 To 65536, 1 To 1), n&
Set fso = CreateObject("scripting.filesystemobject")
Set fld = fso.getfolder(ThisWorkbook.Path)
For Each f In fld.Files
n = n + 1
br(n, 1) = f
Next f
Call digui(br, n, ThisWorkbook.Path)
[a1].Resize(n) = br
End Sub
Sub digui(br, n, p)
Dim fso, fld, f, subfld, fd
Set fso = CreateObject("scripting.filesystemobject")
Set fld = fso.getfolder(p)
Set subfld = fld.subfolders
For Each fd In subfld
For Each f In fd.Files
n = n + 1
br(n, 1) = f
Next f
Call digui(br, n, fd)
Next fd
End Sub
|
|