Hi,
i am looking to display folders of a particular directory in a listbox.
below is the code for the same using 'for each loop'
Private Sub btnForEachLoop_Click(sender As Object, e As EventArgs) Handles btnForEachLoop.Click
'Clearlist
Clearlist()
'List each folder of root of C: drive
For each srtFolder As string in
My.Computer.FileSystem.GetDirectories("C:\")
'add items in listbox
lstData.Items.Add(srtFolder)
Next
End Sub
End Class
MY QUERY:- HOW CAN I PERFORM THE SAME OPERATION USING 'FOR NEXT LOOP'
Below is what i did so far
Private Sub btnFornextLoop_Click(sender As Object, e As EventArgs) Handles btnForNextLoop.Click
'declare variables
Dim Counter As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim intStep As Integer
Counter = My.Computer.FileSystem.GetDirectories("C:\")
'Clear list
Clearlist()
'List each folder at root of C: drive
For intStep = 1 To Counter.Count
'list and add items in listbox
lstData.Items.Add(My.Computer.FileSystem.GetDirectories("C:\"))
Next
End Sub
End Class
but in list box i am getting
(collection)
(collection)
....
instead of folder names.
i am looking to display folders of a particular directory in a listbox.
below is the code for the same using 'for each loop'
Private Sub btnForEachLoop_Click(sender As Object, e As EventArgs) Handles btnForEachLoop.Click
'Clearlist
Clearlist()
'List each folder of root of C: drive
For each srtFolder As string in
My.Computer.FileSystem.GetDirectories("C:\")
'add items in listbox
lstData.Items.Add(srtFolder)
Next
End Sub
End Class
MY QUERY:- HOW CAN I PERFORM THE SAME OPERATION USING 'FOR NEXT LOOP'
Below is what i did so far
Private Sub btnFornextLoop_Click(sender As Object, e As EventArgs) Handles btnForNextLoop.Click
'declare variables
Dim Counter As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim intStep As Integer
Counter = My.Computer.FileSystem.GetDirectories("C:\")
'Clear list
Clearlist()
'List each folder at root of C: drive
For intStep = 1 To Counter.Count
'list and add items in listbox
lstData.Items.Add(My.Computer.FileSystem.GetDirectories("C:\"))
Next
End Sub
End Class
but in list box i am getting
(collection)
(collection)
....
instead of folder names.