从路径列表创建目录树 [英] Make a directory tree from a list of paths

查看:98
本文介绍了从路径列表创建目录树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个充满路径的数组列表,想在树视图中显示它们(就像在Konqueror中一样)
但我不对其进行管理.
示例:
Dir1/
Dir1/SubDir1/SubDir2/
Dir1/SubDir1/AnotherSubDir1/
Dir1/SubDir3/SubDir4/Subdir5/
Dir1/AnotherSubdir2/SubDir5/
它们不是真实目录
请帮助!

非常感谢!!!



I have a arraylist full of paths and want to show them in a treeview( like in Konqueror )
but I do not manage it.
An example:
Dir1/
Dir1/SubDir1/SubDir2/
Dir1/SubDir1/AnotherSubDir1/
Dir1/SubDir3/SubDir4/Subdir5/
Dir1/AnotherSubdir2/SubDir5/
They are no real directories
Please help!

Thanky very much!!!

于2009年8月5日,星期三,9:33修改
modified on Wednesday, August 5, 2009 9:33 AM

推荐答案

您好,

对于列表中的每个条目,必须在列表视图中找到或创建项目.

这是逻辑,并带有示例:

添加"Dir1/SubDir3/SubDir4/Subdir5/"

Dir1是否在列表视图的顶层?是的,因为您已经输入了一些条目.

SubDir3是否在列表视图的Dir1级别中?否,因此创建它

SubDir4是否在Dir1/SubDir3级别?不,请创建它.

等.


您将需要的类包括System.IO.Path类以获取路径部分(或者,您可以使用string.Split)

:)

Hi,

for each entry in the list, you must locate or create the items in the listview.

Here is the logic, with an example:

adding "Dir1/SubDir3/SubDir4/Subdir5/"

is Dir1 in the top level of the listview? yes, since you already did some entries.

is SubDir3 in the Dir1 level of the listview? no, so create it

is SubDir4 in the Dir1/SubDir3 level? no, so create it

etc.


Classes you will need include the System.IO.Path class to get path parts (alternatively you could use string.Split)

:)


这篇关于从路径列表创建目录树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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