文件系统树视图

编程入门 行业动态 更新时间:2024-10-24 18:26:27
本文介绍了文件系统树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用文件系统,并且我有一个以文件路径作为属性的文件对象的 List.基本上我需要在 .NET 中创建一个树视图,但我正在努力想出最好的方法来做到这一点,因为我需要从如下列表中创建一个树结构:

Im working with file systems and I have a List<> of file objects that have the file path as a property. Basically I need to create a treeview in .NET but im struggling to think of the best way to go about doing this as I need to create a tree structure from a list like:

C:/WINDOWS/Temp/ErrorLog.txt C:/Program Files/FileZilla/GPL.html C:/Documents and Settings/Administrator/ntuser.dat.LOG

等等....

该列表根本没有结构化,我无法对当前对象结构进行任何更改.

The list is not structured at all and I cant make any changes to the current object structure.

我正在使用 C#.

非常感谢所有贡献者

推荐答案

如果你想坚持使用字符串,这样的事情会奏效...

If you wanted to stick with the strings something like this would work...

TreeNode root = new TreeNode(); TreeNode node = root; treeView1.Nodes.Add(root); foreach (string filePath in myList) // myList is your list of paths { node = root; foreach (string pathBits in filePath.Split('/')) { node = AddNode(node, pathBits); } } private TreeNode AddNode(TreeNode node, string key) { if (node.Nodes.ContainsKey(key)) { return node.Nodes[key]; } else { return node.Nodes.Add(key, key); } }

更多推荐

文件系统树视图

本文发布于:2023-05-28 06:53:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315072.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   文件系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!