sPath是所查找的文件夹的路径,list是返回的文件列表
| Public Function GetAllFiles(ByVal sPath As String, list As Collection) Dim item As String Dim oPaths As New Collection item = Dir(sPath, vbDirectory) While Len(item) > 0 If item <> "." And item <> ".." Then If (GetAttr(FullPathName(sPath) & item) And vbDirectory) = vbDirectory Then 中国网管论坛bbs.bitsCN.com oPaths.Add item Else If IsModelFile(item) Then list.Add sPath & item End If End If item = Dir Wend Dim p For Each p In oPaths Call GetAllFiles(Combin(sPath, p), list) Next End Function |
判断文件夹后是否有
| Public Function FullPathName(ByVal strPath As String) As String FullPathName = IIf(VBA.Right(strPath, 1) = "/", strPath, strPath & "/") End Function |
多个文件夹名组成路径
|
Public Function Combin(ParamArray arg()) As String |
-------------------------------------
URL:http://www.bitscn.com/dotnet/vb/200807/147175.html
本文提供了一个使用VBA编写的递归函数,用于遍历指定路径下的所有文件和子文件夹,并将文件列表收集到集合中。此功能对于需要处理大量文件的批量任务特别有用。
4111

被折叠的 条评论
为什么被折叠?



