枚举目录的最快方法 [英] Fastest way to enumerate directories

查看:93
本文介绍了枚举目录的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在寻找一种方法来列出所有目录名称以及子目录。我有大约2000多个目录,其中包含子目录。我只需要目录名称及其完整路径。此时不需要其中的文件。我基本上是想从这里创建一个树视图.net的标准方法在获取时看起来很慢。需要大约6秒才能获得清单。



谢谢。



我尝试了什么:



标准方法



List< string>显示目录=新列表与LT;字符串>(Directory.EnumerateDirectories(目录, *,SearchOption.AllDirectories));

解决方案
有些信息在这里:c# - 提高列举使用.NET文件和文件夹的性能 - 堆栈溢出 [ ^ ]。


您是否同时使用所有这些信息填充树控件?



你真的没必要。您所做的只是填充树的顶层。然后,您为每个节点提供一个虚拟节点,这样您就可以使用+来展开它。当用户单击该节点进行展开时,您将删除虚拟节点并立即获取该节点下的所有文件夹并填充它们。这根本不需要任何时间。


Hi,

I am searching for a method to list out all directories names along with sub directories. I have around 2000+ directories with sub directories within then. I just need the directory names with their full path. The files within then are not needed at this moment. I am basically trying to create a tree view from this.The standard method of .net seems very slow in fetching. Takes around 6 secs to get the list.

Thanks.

What I have tried:

The standard method

List<string> dirs = new List<string>(Directory.EnumerateDirectories(DirectoryPath,"*",SearchOption.AllDirectories));

解决方案

Some info here: c# - Improve the performance for enumerating files and folders using .NET - Stack Overflow[^].


Are you populating the tree control with all of this information at the same time?

You really don't have to. All you do is populate the top level of the tree. You then give every node a "dummy" node under it so you get the "+" to expand it. When the user clicks that node to expand, you remove the dummy node and go get all the folders immediately under that node and populate them. That doesn't take any time at all.


这篇关于枚举目录的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆