none
Explorer Style Application RRS feed

  • Question

  • Hi All,

           I have to create a application which will display all the contents of a hard disk (let us say D:\ drive) in a tree view i.e look and feel like Windows Explorer this would do using Directory.GetFileSystemEntries(path) but this would not return the content of the sub directories if i had to do that i have to use Directory.GetDirectories(path) in a loop, is there any other way of doing this which will give me the entire details in of a drive

    Regards
    Archana Muralidhar

    achu
    Wednesday, October 15, 2008 1:36 PM

Answers

All replies

  • Wednesday, October 15, 2008 3:33 PM
  • Hi Pranav

            The second link that you sent works like a charm.... but its very slow... is there a way to optimize the speed

    Regards
    Archana Muralidhar
    achu
    Thursday, October 16, 2008 9:31 AM
  • Archana Muralidhar said:
    I have to create a application which will display all the contents of a hard disk (let us say D:\ drive) in a tree view i.e look and feel like Windows Explorer this would do using 
    Directory.GetFileSystemEntries(path) but this would not return the content of the sub directories if i had to do that i have to use Directory.GetDirectories(path) in a loop, is there any other way of doing this which will give me the entire details in of a drive.

     

    Thank you Pranav for your friendly help.

    Hi Archana,

    Here is one code sample for you to try:
    Retrieve all files and subfolders from a directory and display file hiberarchy structure on TreeView control.
    Prerequisites: Drag&drop TreeView1 onto Form1.

    Imports System.IO  
     
    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            ' Specify the root folder    
            Dim rootFolder As String = "D:\DELL Driver" 
            ' Add full path of the rootFolder to TreeView    
            Dim myNode As TreeNode = Me.TreeView1.Nodes.Add(rootFolder)  
            Me.NextNode(myNode, rootFolder)  
        End Sub 
     
        ' Recursive method    
        Private Sub NextNode(ByVal NodeIn As TreeNode, ByVal DirectoryIn As String)  
            Dim directory As New DirectoryInfo(DirectoryIn)  
            Dim MyNode As TreeNode  
     
            'Add name (not FullName) of all subfolders as SubNodes to TreeView    
            Dim mydirectories() As DirectoryInfo = directory.GetDirectories()  
            For Each Item As DirectoryInfo In mydirectories  
                MyNode = NodeIn.Nodes.Add(Item.Name)  
                Me.NextNode(MyNode, Item.FullName)  
            Next 
     
            'Add name (not FullName) of all files as SubNodes to TreeView    
            Dim myfiles() As FileInfo = directory.GetFiles()  
            For Each Item As FileInfo In myfiles  
                MyNode = NodeIn.Nodes.Add(Item.Name)  
            Next 
     
        End Sub 
     
    End Class 

    Here is the corresponding screenshot:



    Best regards,
    Martin Xie

    Wednesday, October 22, 2008 6:38 AM
  •  Hi Martin,

          i had used a code which goes something like below

     

    Dim NameDir As IO.DirectoryInfo  
     
    Dim MyNode, MyNode1 As TreeNode  
     
    'FIrst Folder and File list  
     
    If IO.Directory.Exists(DirTree) Then 
     
    For Each MyDir As String In IO.Directory.GetDirectories(DirTree)  
     
    NameDir = New IO.DirectoryInfo(MyDir)  
     
    'Call AddIcon(NameDir.ToString)  
     
    'MyNode = TrFoldList.Nodes.Add(NameDir.Name)  
     
    MyNode = stnode.Nodes.Add(NameDir.Name)  
     
    'MyNode.ImageIndex = iconIn  
     
    'MyNode.SelectedImageIndex = iconIn  
     
    If IO.Directory.Exists(NameDir.ToString) Then 
     
    For Each MyDir1 As String In IO.Directory.GetFiles(NameDir.ToString)  
     
    NameDir = New IO.DirectoryInfo(MyDir1)  
     
    'Call AddIcon(NameDir.ToString)  
     
    If Not (NameDir.Name = "Thumbs.db"Then 
     
    MyNode1 = MyNode.Nodes.Add(NameDir.Name)  
     
    MyNode1.Tag = MyDir1  
     
    End If 
     
    'MyNode1.ImageIndex = iconIn  
     
    'MyNode1.SelectedImageIndex = iconIn  
     
    Next 
     
    End If 
     
    If IO.Directory.Exists(MyDir) Then 
     
    Call DisplayTree(MyDir, MyNode)  
     
    End If 
     
    Next 
     
    End If 


    and the code that you have given will work at the speed and this so is there any way which will speed up the process



    achu
    Thursday, October 23, 2008 11:03 AM