My directory structure is like below.
dir2
tow main directories and subdir1_1 have 2 sub-directories (subdir1_1_1 ,subdir1_1_2) and subdir1_1_1 have sub-directory "subdir1_1_1_1"
Ok
Now I have this code
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim BaseFolder As New IO.DirectoryInfo(Me.TextBox1.Text)
For Each f As IO.DirectoryInfo In BaseFolder.GetDirectories()
AddContents(f)
Next
End Sub
Sub AddContents(ByVal BaseFolder As IO.DirectoryInfo)
For Each subF As IO.DirectoryInfo In BaseFolder.GetDirectories()
ListBox1.Items.Add(BaseFolder.FullName)
AddContents(subF)
Next
End Sub
End Class
and my textbox1.text= "C:\test"
and the result doesn't have subdir1_1_1_1 and subdir1_1_2 . why ??
where the problem?? why I can't get the empty folder ? enter image description here
Try it this way
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim BaseFolder As New IO.DirectoryInfo(Me.TextBox1.Text)
ListBox1.Items.Clear()
AddContents(BaseFolder)
End Sub
Sub AddContents(ByVal BaseFolder As IO.DirectoryInfo)
ListBox1.Items.Add(BaseFolder.FullName)
For Each subF As IO.DirectoryInfo In BaseFolder.GetDirectories()
AddContents(subF)
Next
End Sub