有更好的方法(更快)来做同样的事情吗?如果有很多文件夹。
我对算法了解一点,我希望有人能给我一个更好的算法。
我使用代码完成了以下工作:
private static void ShowAllFoldersUnder(string path, int indent)
{
try
{
if ((File.GetAttributes(path) & FileAttributes.ReparsePoint)
!= FileAttributes.ReparsePoint)
{
foreach (string folder in Directory.GetDirectories(path))
{
Console.WriteLine(
"{0}{1}", new string(' ', indent), Path.GetFileName(folder));
ShowAllFoldersUnder(folder, indent + 2);
}
}
}
catch (UnauthorizedAccessException ex) {
Console.WriteLine(ex.Message);
}
}输出样本结果
CompositeUI
BuilderStrategies
Collections
Commands
Configuration
Xsd
EventBroker
Instrumentation
obj
Debug
TempPE
Properties
Services
SmartParts
UIElements
Utility
Visualizer发布于 2015-08-26 03:19:36
EnumerateDirectories可能更快,因为它不必像GetDirectories那样分配文件夹名数组。
https://stackoverflow.com/questions/32217137
复制相似问题