如何使用Treeview扫描目录和子目录? [英] How to scan directories and subdirectories with treeview?

查看:106
本文介绍了如何使用Treeview扫描目录和子目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我会再一次尝试最好的问题.我已经看到其他程序使用树形视图来获取扫描目录或路径.我要做的就是使用树状视图选择要从中开始扫描的路径.我的form1包含一个名为Tv1的树视图,一个名为lblmessage的标签和一个开始按钮.我需要在目录中进行迭代或反复扫描,而不是添加或查找目录.我认为过去为我提供帮助的尝试已经说明了如何添加目录和子目录,这与我所需要的完全相反.请问有人逐步给出解决方案如何完成此任务?

指出我需要的形式:

1)如果可能,使用带有根目录,文件夹,子文件夹,文件的工作树视图
2)开始按钮,可反复扫描并激活用户选择的选定树视图节点
3)显示正在扫描的当前文件夹,路径,文件的标签.


就是这样............

在此先谢谢您

Ok I will try once more to ask this question as best I can. I have seen other programs use a treeview to obtain a scanning directory or path. All im aiming to do is use a treeview to select a path to start my scan from. My form1 contains a treeview named Tv1, A label named lblmessage and a start button. I need to itterate or recrusively scan through the directory, not to add or find directories. I think past attempts to help me with this have explained how to add directories and subdirectories which is quite the oppsite of what i need. Will someone please give a solution step by step how to complete this task?

Point form what I need:

1) Working treeview with root,folders,subfolders,files if possible
2) start button that recrusivly scans and itterates the selected treeview node selected by the user
3) a label that displays the current folder,path,file being scanned.


thats it............

thank you in advance

推荐答案

您说:

我需要遍历目录或进行递归扫描,而不是添加或查找目录."

相反,为了填充树视图,您需要找到目录.

确定要扫描哪个文件夹的方式完全取决于您如何填充树.您是将整个路径存储在某个位置还是仅存储文件夹名称?如果存储了整个路径,那么您要做的就是将存储的路径解析到所选的子文件夹中.您可以通过计算必须备份到树中的根节点的次数来确定这一点.如果您只是存储了文件夹名称(或者宁愿只是这样操作,这就是我的想法),则必须备份到树中并获取父节点名称,直到达到根节点,然后逐步构建反向路径.

我怀疑您会获得分步说明,因为我们不了解您的所有要求,也不了解围绕此要求的代码.
You said:

"I need to iterate or recursively scan through the directory, not to add or find directories."

On the contrary, in order to populate the treeview, you need to find directories.

The way you determine what folder to scan depends entirely on how you populated the tree. Did you store the entire path somewhere, or just the folder name? If you stored the entire path, all you have to do is parse the stored path down to the selected sub-folder. You can determine that by counting how many times you have to backup to the root node in the tree. If you just stored the folder name (or if you''d rather just do it this way, which is how I would feel about it), you have to backup in the tree and get the parent node name(s) until you reach the root node, and build the path backwards as you go.

I doubt you''ll get step-by-step instructions because we don''t know all of your requirements, nor the code that surrounds this requirement.


这篇关于如何使用Treeview扫描目录和子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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