0
是否有更好的方法(更快)做同样的事情?如果有很多的文件夹。
我对算法有所了解,希望有人能为我提供一个更好的算法。最快最简单的方法输出文件夹递归树
我使用的代码如下工作:
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
使用此代码很多次。这十分完美。 – jdweng