[英]How to get the directory without sub directory in c#
I would like to ask is there any way to get all the folder/directory name in a path:我想问一下有什么方法可以获取路径中的所有文件夹/目录名称:
My problem is:我的问题是:
I would like to get several folders in Local Disk C: but I don't want to use the following code to search all the folder in C: which causes the program stuck.我想在本地磁盘 C: 中获取多个文件夹,但我不想使用以下代码搜索 C: 中的所有文件夹,这导致程序卡住。
foreach (string dirPath in Directory.GetDirectories(source, "*", SearchOption.AllDirectories))
{
...
}
Try this:尝试这个:
using System.IO;
var directories = Directory.GetDirectories("c:\\");
This should give you all the directories at the root level of the C drive.这应该为您提供 C 驱动器根级别的所有目录。
Try this:尝试这个:
string[] dirs = Directory.GetDirectories(@"c:\", "*", SearchOption.TopDirectoryOnly);
This should give you just top directory only.这应该只给你顶级目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.