这个是取得一个夹下的所有文件:
Function AutoListFiles(ByVal sDirName As String, ByVal FileFilter As String) As String
On Error GoTo RF_ERROR
'sDirName是文件夹,可以是上个函数用split拆分后的每个夹,你可以用个数组将二者结合起来用,忘记说了,上个函数是取得所有文件夹的串,以vbNullChar为分隔符,出错的地方可以暂时注释掉
'FileFilter 是文件类型,如"*.JPG"
Dim sFile As String
Dim sDirNameTmp As String
Function GetAllFolder(ByVal strFolderStart As String) As String
On Error GoTo ErrHandler
Static booRunNing As Boolean
Dim colAllDirs As New Collection
Dim lngNextDir As Long
Dim lngI As Long
Dim strDirName As String
Dim strDirStar As String
Dim strSubDir As String
Dim cur As New CWaitCursor
If booRunNing Then
Exit Function
Else
booRunNing = True
cur.ShowCursor "检查文件夹...", vbHourglass
Do While strSubDir <> ""
' 添加路径名称到列表
If UCase(strSubDir) <> "PAGEFILE.SYS" And strSubDir <> "." And strSubDir <> ".." Then
strSubDir = strDirName & "\" & strSubDir
'它是一个路径
If (GetAttr(strSubDir) And vbDirectory) = vbDirectory Then colAllDirs.Add strSubDir
End If
strSubDir = Dir(, vbDirectory)
DoEvents
Loop
DoEvents
If Not booRunNing Then Exit Do
Loop
GetAllFolder = "" '因递归调用,故此句不能省略
For lngI = 1 To colAllDirs.Count
GetAllFolder = GetAllFolder & colAllDirs(lngI) & vbNullChar
Next lngI
booRunNing = False
End If
If GetAllFolder <> "" Then GetAllFolder = Left(GetAllFolder, Len(GetAllFolder) - Len(vbNullChar))
exi:
Exit Function
ErrHandler:
MsgBox "错误号:" & Err.Number & vbCrLf & Err.Description, vbInformation
End Function