Hi all,

I need to list all files in directory.
How i can do this.

Thank you

Recommended Answers

All 3 Replies

Dim di As New IO.DirectoryInfo("Your directory path")
                    Debug.Print("di: " + di.ToString)
                    Dim diar1 As IO.FileInfo() = di.GetFiles()
                    Dim dra As IO.FileInfo
                    'list the names of all files in the specified directory
                    For Each dra In diar1
                        lstFiles.Items.Add(dra) 'all files present in the directory are viewed in list box

hope it helps u...

commented: VB.Net solution for VB6 ? -3

See if this help :

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$
End Sub

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

See this thread

commented: Worked nice :) +3

@poojavb : Than you for replying but i'm using vb6 to do this.
@Jx_Man : Thank you for complete code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.