Reputation:
Can't seem to find a way to do this, google is failing me!
Please help, thank you!
Upvotes: 10
Views: 69069
Reputation: 11
di = New DirectoryInfo(path)
rgFiles = di.GetFiles("*.*", IO.SearchOption.AllDirectories)
For Each fi As FileInfo In rgFiles
If CheckIfExist(fi.FullName.ToString.Replace("\" & fi.Name, "")) = False Then
ListBox1.Items.Add(fi.FullName.ToString.Replace("\" & fi.Name, ""))
End If
Next
Public Function CheckIfExist(ByRef Path As String) As Boolean
Dim RetVal As Boolean = False
For Each LI As String In ListBox1.Items
If LI.ToString = Path Then
RetVal = True
Return RetVal
Exit Function
End If
Next
Return RetVal
End Function
Upvotes: 0
Reputation: 351516
Try this:
Imports System
Imports System.IO
Class Program
Shared Sub Main()
For Each Dir As String In Directory.GetDirectories("c:\Program Files")
Console.WriteLine(Dir)
Next
End Sub
End Class
I am using the Directory.GetDirectories
method which returns an array of strings, one for each subdirectory of the directory I provide as a parameter to the method.
Upvotes: 21