使用filesystemobject获取文件夹及子文件夹下所有文件名

 1 Option Explicit
 2 Dim i
 3 Function sda(path)
 4     Dim fso
 5     Dim f
 6     Dim s
 7     Dim ff
 8     Set fso = CreateObject("scripting.filesystemobject")
 9     Set f = fso.getfolder(path)
10     For Each s In f.Files
11         i = i + 1
12         Range("A" & i) = path & "\" & s.Name
13     Next
14     
15     For Each ff In f.subfolders
16         Call sda(ff)
17     Next
18     Set ff = Nothing
19     Set fso = Nothing
20 End Function
21 
22 Sub dddd()
23     Dim path  As String
24     path = "C:\Users\lison\Desktop\新建文件夹"
25     sda (path)
26 End Sub

 

posted on 2023-07-26 10:48  松梅  阅读(95)  评论(0编辑  收藏  举报

导航