VB得到指定文件夹下的文件列表

来源:互联网 发布:什么编程语言最难学 编辑:程序博客网 时间:2024/05/22 10:53
Function GetFileList(ByVal Path As StringByRef FileName() As StringOptional 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 - 1As 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
 
原创粉丝点击