看看这个代码可以不
Public Function funFindDirectory(ByVal strDir As String, Optional vMode As Long = vbDirectory) As Integer
Dim vFileNames As String
Dim vLoop As Integer
Dim vFileAttr As FILEATTRIB
varFileCount = 0
varDirCount = 0
On Error GoTo lopErr
If strDir = "" Then
strDir = varCurrentPath
End If
If Right(Trim(strDir), 1) <> "\" Then
strDir = Trim(strDir) & "\"
End If
strDir = UCase(strDir)
vFileNames = Dir(strDir, vMode)
ReDim Preserve vFiles(11)
ReDim Preserve vDirectories(11)
Err.Clear
Do While vFileNames <> ""
varCurrentPath = strDir
If vFileNames <> "." And vFileNames <> ".." Then
If (GetAttr(strDir & vFileNames) And vbDirectory) = vbDirectory Then
If varDirCount Mod 10 = 0 Then
ReDim Preserve vDirectories(varDirCount + 10)
DoEvents
End If
funGetFileAttrib strDir & vFileNames, vDirectories(varDirCount)
varDirCount = varDirCount + 1
Else
If varFileCount Mod 10 = 0 Then
ReDim Preserve vFiles(varFileCount + 10)
DoEvents
End If
funGetFileAttrib strDir & vFileNames, vFiles(varFileCount)
varFileCount = varFileCount + 1
End If
End If
lopErr:
vFileNames = Dir(, vbAlias)
Loop
funQuickSortFile vDirectories(), 0, varDirCount - 1
funQuickSortFile vFiles(), 0, varFileCount - 1
Exit Function
'vErrorMessage = "File Not Found."
End Function