无法找到办法做到这一点,谷歌让我失望!
请帮助,谢谢!
答案 0 :(得分:14)
试试这个:
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
我正在使用Directory.GetDirectories
方法返回一个字符串数组,一个用于我提供的目录的每个子目录作为方法的参数。
答案 1 :(得分:4)
DirectoryInfo di = new DirectoryInfo("path");
di.GetDirectories();
答案 2 :(得分:0)
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