vb.net 列出目录中的所有文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1338668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:22:27 来源:igfitidea点击:
List All Folders in Directory
提问by Josh
Can't seem to find a way to do this, google is failing me!
似乎找不到办法做到这一点,谷歌让我失望了!
Please help, thank you!
请帮忙,谢谢!
回答by Andrew Hare
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.
我使用的Directory.GetDirectories
方法返回一个字符串数组,一个用于我作为方法参数提供的目录的每个子目录。
回答by Josh
DirectoryInfo di = new DirectoryInfo("path");
di.GetDirectories();
回答by Hemant Patil
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