代码如下:
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
Private Sub Command1_Click()
Dim FileName() As String, i As Long
GetFileList "c:", FileName, "*.mp3" '可以设置文件类型
For i = 0 To UBound(FileName)
Print FileName(i)
Next i
End Sub