c# 获取文件夹下面所有文件夹列表
2020-12-13 14:15
标签:style blog io color ar for sp 文件 div 方法一: 方法二: c# 获取文件夹下面所有文件夹列表 标签:style blog io color ar for sp 文件 div 原文地址:http://www.cnblogs.com/akiing/p/4060020.html string dirPath = @"D:\App1";
Liststring> dirs = new Liststring>(Directory.GetDirectories(dirPath, "*", System.IO.SearchOption.AllDirectories));
foreach (var dir in dirs)
{
Console.WriteLine("{0}", dir);
}
Console.WriteLine("{0} directories found.", dirs.Count);
string dirPath = @"D:\App1";
Liststring> dirs = ListDirectory(dirPath);
private static Liststring> ListDirectory(string dirPath)
{
Liststring> dirs = new Liststring>(Directory.EnumerateDirectories(dirPath));
Liststring> result = new Liststring>();
foreach (var dir in dirs)
{
result.Add(string.Format("{0}", dirPath + "\\" + dir.Substring(dir.LastIndexOf("\\") + 1)));
Console.WriteLine("{0}", dirPath + "\\" + dir.Substring(dir.LastIndexOf("\\") + 1));
result.AddRange(ListDirectory(dir));
}
return result;
}