这个函数可以遍历指定一个目录下的所有文件,包括子目录.也可以指定文件类型遍历。
Private Function SearchFiles(Path As String, FileType As String)
Dim Files() As String '文件路径
Dim Folder() As String '文件夹路径
Dim a, b, c As Long
Dim sPath As String
If Right(Path, 1) <> "\" Then Path = Path & "\"
sPath = Dir(Path & FileType) '查找第一个文件
Do While Len(sPath) '循环到没有文件为止
a = a + 1
ReDim Preserve Files(1 To a)
Files(a) = Path & sPath '将文件目录和文件名组合,并存放到数组中
List1.AddItem Files(a) '加入list控件中
sPath = Dir '查找下一个文件</