Hello everyone
i want to get all file in a folder to a listbox using visual basic 6.0

example:
i have many files in a foldre mp3,dat,mpg etc file in D:\musicfolder
and we use a listbox and a timer or command botton
when i click on command botton then listbox additems to D:\musicfolder
please help me to solve this problem
Thanks

See if this helps :

Private Sub ListFiles(strPath As String, Optional Extention As String)
'Leave Extention blank for all files
    Dim File As String
       
    If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
       
    If Trim$(Extention) = "" Then
        Extention = "*.*"
    ElseIf Left$(Extention, 2) <> "*." Then
        Extention = "*." & Extention
    End If
       
    File = Dir$(strPath & Extention)
    Do While Len(File)
        List1.AddItem File
        File = Dir$
    Loop
End Sub

To get all files :

Private Sub Command1_Click()
ListFiles "D:\musicfolder", "*" ' Or ListFiles "D:\musicfolder", "" leave it blank to get all files
End Sub

Just get mpg files :

Private Sub Command1_Click()
ListFiles "D:\musicfolder", "mpg" 'mpg files
End Sub

Edited 4 Years Ago by Jx_Man: Edit code

This question has already been answered. Start a new discussion instead.