7,766
社区成员
发帖
与我相关
我的任务
分享
Function SearchFiles(ByVal BasePath As String, Optional ByVal searchPattern As String = "*.*") As Collection
Dim colPathStack As Collection, colFiles As Collection
Dim sPath As String, sFound As String
Set colFiles = New Collection
Set colPathStack = New Collection
colPathStack.Add BasePath & IIf(Right$(BasePath, 1) <> "\", "\", vbNullString)
While colPathStack.Count <> 0
sPath = colPathStack(1)
colPathStack.Remove 1
sFound = Dir(sPath & "*.*", vbDirectory + vbHidden)
While LenB(sFound)
If (sFound <> ".") And (sFound <> "..") Then
If (GetAttr(sPath & sFound) And vbDirectory) <> 0 Then
colPathStack.Add sPath & sFound & "\"
End If
End If
sFound = Dir()
Wend
sFound = Dir(sPath & searchPattern, vbHidden)
While LenB(sFound)
colFiles.Add sPath & sFound
Debug.Print sPath & sFound
sFound = Dir()
Wend
Wend
Set SearchFiles = colFiles
End Function