Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the current way Ive got inst working well it sometimes doesn't work is there another way to the one below or a way to improve :
Sub scanSubfolders(ByVal FolderLocation As String, ByVal lstbox As ListBox)
        For Each s In My.Computer.FileSystem.GetFiles(FolderLocation)
            Try
                lstbox.Items.Add(s)

            Catch ex As Exception

            End Try
        Next
        For Each s In My.Computer.FileSystem.GetDirectories(FolderLocation)
            Try
                scanSubfolders(s, ListBox1)
            Catch ex As Exception

            End Try
        Next
    End Sub

cheers


oh and form load
scanSubfolders(My.Computer.FileSystem.SpecialDirectories.Temp, Me.ListBox1)


What I have tried:

i wrote above what ive tried ect so hope someone could help.
Posted
Updated 15-Oct-17 3:25am
v2
Comments
A_Griffin 15-Oct-17 8:19am    
There are dozens of code examples on the Internet showing how to do this. Just Google "vb.net list files folders recursive" or similar

1 solution

Oh, here you go:
VB
Imports System.IO

 Private Sub scanFolders(ByVal FolderLocation As String)
      Try
         For Each d In Directory.GetDirectories(FolderLocation)
            ListBox1.Items.Add(d)
            For Each f In Directory.GetFiles(d, "*.*")
               ListBox1.Items.Add(f)
            Next
            scanFolders(d)
         Next
      Catch ex As Exception
         ' log error
      End Try
   End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900