扫描具有树视图的文件夹和子文件夹,所有工作都需要帮助 [英] Scan folders and subfolders with treeview all most working need help please

查看:51
本文介绍了扫描具有树视图的文件夹和子文件夹,所有工作都需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所有这些都是最有效的,但现在我需要看到它的工作,需要一些进一步的帮助才能获得我想要的效果。到目前为止我的树视图代码是:

Ok so this is all most working but now I need to see it work and need just a bit of further assistance to get the desired effect that im looking for. the code I have so far for my treeview is:

Imports System.IO
Public Class form1

    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tv1.Nodes.Clear()
        For Each drv As DriveInfo In My.Computer.FileSystem.Drives
            If drv.IsReady Then Call LoadFolderTree(drv.Name)
        Next
        tv1.Nodes(0).Expand()
        On Error Resume Next
        tv1.Nodes(1).Expand()
    End Sub

    Public Sub LoadFolderTree(ByVal path As String)
        Dim basenode As System.Windows.Forms.TreeNode, volbl As String, drvltr As String = path
        If IO.Directory.Exists(path) Then
            If path.Length <= 3 Then
       volbl = My.Computer.FileSystem.GetDriveInfo(path).VolumeLabel
       If Len(drvltr) = 3 Then drvltr = Mid(drvltr, 1, 2)
       basenode = tv1.Nodes.Add(String.Format("{0} ({1})", volbl, drvltr))
            Else
            basenode = tv1.Nodes.Add(My.Computer.FileSystem.GetName(path))
            End If
            basenode.Tag = path
            LoadDir(path, basenode)
        Else
            Throw New DirectoryNotFoundException()
        End If
    End Sub

    Private Sub tv1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tv1.AfterSelect
        lblMessage.Text = tv1.SelectedNode.Tag
    End Sub

    Private Sub tv1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tv1.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim snd As TreeNode = tv1.SelectedNode
            On Error Resume Next
            tv1.CollapseAll()
            snd.Expand()
            tv1.SelectedNode = snd
        End If
    End Sub

Private Sub tv1_AfterExpand(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tv1.AfterExpand
        Dim n As System.Windows.Forms.TreeNode
        For Each n In e.Node.Nodes
            LoadDir(n.Tag, n)
        Next
    End Sub
Public Sub LoadDir(ByVal DirPath As String, ByVal Node As Windows.Forms.TreeNode)
        On Error Resume Next
        Dim Dir As String, DirName As String, Index As Integer
        If Node.Nodes.Count = 0 Then
        For Each Dir In My.Computer.FileSystem.GetDirectories(DirPath)
        Index = Dir.LastIndexOf("\") : DirName = Dir.Substring(Index + 1, Dir.Length - Index - 1)
       If fncAddThisDir(DirName) Then Node.Nodes.Add(DirName) : Node.LastNode.Tag = Dir : Node.LastNode.ImageIndex = 0
            Next
        End If
    End Sub

    Function fncAddThisDir(ByVal dirname As String) As Boolean
        If Mid(LCase(dirname), 1, 7) = "program" Then dirname = "Program"
        Select Case LCase(dirname)
            Case ""
            Case "$avg","$recycle.bin"
            Case "recycler", ".wd_tv"
            Case Else : fncAddThisDir = True
        End Select
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        LookAtDir(lblMessage.Text.ToString)

    End Sub
    Private Sub LookAtDir(ByVal path As String)
        Try
            For Each dir As String In Directory.GetDirectories(path)
                LookAtDir(dir)
            Next
            Do something with the directory.
        Catch ex As UnauthorizedAccessException
        End Try
    End Sub
End Class



简而言之,我想要一个可以显示所有硬盘及其文件夹/子文件夹的树视图。然后用户单击所需的根,例如C:\或D:\ ect,然后单击开始........

然后文本框显示正在扫描的当前文件夹,直到eof。 ...


In short I want a treeview that can show all hard drives and their folders/subfolders. The user then clicks the desired root such as C:\ or D:\ ect and clicks start........
The textbox then shows the current folder being scanned untill eof....

推荐答案

avg,
avg","


recycle.bin
案例 recycler 。wd_tv
案例 其他:fncAddThisDir =
结束 选择
结束 功能

私有 Sub Button1_Cl ick( ByVal sender As System。 Object ByVal e As System.EventArgs) Handles Button1.Click
LookAtDir( lblMessage .Text.ToString)

结束 Sub
私有 Sub LookAtDir( ByVal 路径作为 字符串
尝试
对于 每个 dir 作为 字符串 目录.GetDirectories(路径)
LookAtDir(dir)
下一步
目录。
Catch ex As UnauthorizedAccessException
结束 尝试
结束 Sub
结束
recycle.bin" Case "recycler", ".wd_tv" Case Else : fncAddThisDir = True End Select End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click LookAtDir(lblMessage.Text.ToString) End Sub Private Sub LookAtDir(ByVal path As String) Try For Each dir As String In Directory.GetDirectories(path) LookAtDir(dir) Next Do something with the directory. Catch ex As UnauthorizedAccessException End Try End Sub End Class



简而言之,我想要一个可以显示所有硬盘及其文件夹/子文件夹的树视图。然后用户单击所需的根,例如C:\或D:\ ect,然后单击开始........

然后文本框显示正在扫描的当前文件夹,直到eof。 ...


In short I want a treeview that can show all hard drives and their folders/subfolders. The user then clicks the desired root such as C:\ or D:\ ect and clicks start........
The textbox then shows the current folder being scanned untill eof....


您好,



1. lblmessage文本框中的当前文件夹名称。我无法在任何地方看到您将当前文件夹的名称分配给文本框的文本属性,因此您只能看到您在树视图中选择的文件夹的名称,而不是子文件夹名称。

为此你需要修改LookAtDir方法,你可以在其中为lblMessage.Text属性分配路径。你应该在foreach语句之前在LookAtDir方法中编写以下语句。



Hi,

1. Current folder name in lblmessage textbox. I can not see anywhere that you are assigning current folder's name to the text property of the textbox hence you will be able to see only the name of the folder which u have selected in the treeview, not the children folder names.
For that you need to modify LookAtDir method where you assign path to the lblMessage.Text Property. you should write the following statement in LookAtDir method before foreach statement.

lblMessage.Text= path;





2.扫描完成后的消息框。在Button_Click中,在调用LookAtDir方法之后,你应该编写代码来显示messagebox。



我希望这会对你有帮助。



谢谢和问候,

Chetan Ranpariya



2. Messagebox when scan has finished. In Button_Click, after calling LookAtDir Method you should write code to display messagebox.

I hope this will help you.

Thanks and regards,
Chetan Ranpariya


这篇关于扫描具有树视图的文件夹和子文件夹,所有工作都需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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