Type SearchInfo
FileList As String
FileCount As Integer
End Type
'===============================================================================
'-函数名称: SearchFiles
'-功能描述: 遍历目录搜索指定格式的文件
'-输入参数说明: 参数1: 必选 strPath As String 需要搜索的文件夹路径
' 参数2: 可选 strSearch As String 搜索的关键字可使用通配符,不设置将搜索所有文件类型
'-返回参数说明:
'-使用语法示例: Call SearchFiles("C:\") 搜索C盘的所有文件
'-参考: Office帮助
'-使用注意: 需要引用Microsoft Office 10.0 Object Library 或更高版本
'-兼容性: XP,2003
'-作者: fan0217@163.com
'-更新日期: 2006-05-26
'===============================================================================
Function fSearchFile(strPath As String, Optional strSearch As String = "*.*") As SearchInfo
On Error GoTo Err_fSearchFile
Dim fs As FileSearch, i As Long
Dim strFileList As String
Set fs = Application.FileSearch
With fs
.LookIn = strPath
.FileName = strSearch
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
strFileList = strFileList & .FoundFiles(i) & ";"
Next i
End If
End With
Function GetFileList(strFilePathName As String) As String
On Error GoTo Err_GetFileList
Dim strDir As String
strDir = Dir(strFilePathName)
Do
GetFileList = GetFileList & strDir & ";"
strDir = Dir
i = i + 1
If strDir = "" Then Exit Do
Loop