' 获得指定目录下的所有文件的文件名列表
' Path 为目录的绝对路径, FileName() 为返回的文件名数组,fExp为返回的文件类型
Function GetFileList(ByVal Path As String, ByRef Filename() As String, Optional fExp As String = "*.*") As Boolean
Dim fName As String, i As Long
If Right$(Path, 1) <> "\" Then Path = Path & "\"
fName = Dir$(Path & fExp)
i = 0
Do While fName <> ""
ReDim Preserve Filename(i) As String
Filename(i) = fName
fName = Dir$
i = i + 1
Loop
If i <> 0 Then
ReDim Preserve Filename(i - 1) As String
GetFileList = True
Else
GetFileList = False
End If
End Function
MyPath = "E:\AAA"
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> ""
' 跳过当前的目录及上层目录。
If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print "文件:" & MyName
End If
End If
'查找下一个对象
MyName = Dir
Loop