取得指定路径下的所有文件包括文件夹

'在使用下面的代码之前一定要导入包文件(Mictosoft Scripting Runtime),否则有一些文件无法执行过去


dim
arrFiles(1 to 100) dim cntFile sub GetFile_click() dim strPath as string dim fso as new FileSystemObject dim fd as Folder strPath = ThisWork.Path & "" cntFile = 0 set fd = fso.GetFolder(strPath) call searchFiles(fd) Activesheet.range("A1").Resize(cntFile) = Application.Transponse(arrFiles) end sub sub searchFiles(byval fd as folder) dim fl as file dim sfd as folder for each fl in fd.files cntFile = cntFile + 1 arrFiles(cntFile) = fl.path next if fd.subfolders.count = 0 then exit sub end if for each sfd in fd.subfolders call searchFiles(sfd) next end sub

 

posted @ 2018-08-07 12:33  不刷牙的大虫子  阅读(194)  评论(0编辑  收藏  举报