Resolved How to retrieve all directories on each drive quickly?

MrSpeck

Member
Joined
Jul 1, 2008
Messages
7
Programming Experience
1-3
Hi all,

I've made an treeview application with checkboxes beside each directory.

I have a few drives here (including mapped network drivres), linked to servers etc, so when loading the form I'm recursively building the treeview.

The problem is, it takes quite a while to build just the C:, then the mapped network drivers etc, surely there is a quicker way to do this?

Otherwise everytime a user uses my program to check the boxes I'll have to display a message "Please wait while the directories are being built" etc, it won't look very professional. :(

Here is a bit of the code on how I build the treeview.
VB.NET:
        On Error Resume Next

        Dim node As TreeNode

        'Loop through each folder in the directory
        For Each di As IO.DirectoryInfo In _
            New IO.DirectoryInfo(dir).GetDirectories()

            'Add a new node
            node = New TreeNode(di.Name)
            rootNode.Nodes.Add(node)

            'If there are subfolders, then loop through them
            If di.GetDirectories().Length > 0 Then
                AddDirectory(node, di.FullName)

            End If

        Next
So, if there a quicker way? I'm aiming to make some backup software, so it would be nice for the user to be able to select the directories they wish to backup, without having to wait each time for the directories to be built!

Appreciate any help.

Thanks,
Ricky
 
What I would do in your case is, instead of building the entire Tree of all folders (and subfolders and subfolders) for all drives all at once, I would build the top level only at first. I would show all of the drives including the mapped network drives. Then when the users expands a drive you grab just the top level folders for that drive. Then when the user expands a folder, you only grab the top level folders in that folder.

See where I'm going with this? It only takes a fraction of a second to list all of the folders in one folder so instead of building the entire TreeView all in one swoop (which will take forever) you only grab the next piece that the user wants.

I've got a project coming up soon (probably in a week) where I'll be needing to do something like this so I could write a little demo for ya, if you're interested.
 
Great idea...

Thanks for your reply :)

Excellent idea too, that would be a much better approach.

I also wouldn't mind seeing your demo if you didn't mind. :)

Thankyou.
 
So, if there a quicker way? I'm aiming to make some backup software, so it would be nice for the user to be able to select the directories they wish to backup, without having to wait each time for the directories to be built!

Erm. You seem to be worried that every other manufacturer out there actually enumerates ALL folders before showing the tree, and knows some trick to make the whole of C: enumerate instantly, that you dont..

How about Microsoft.. in old versions of explorer.. did you ever notice that when youre using folders view, you expand it and EVERY folder has a + sign next to it? EVEN THOSE WITH NO SUBFOLDERS?

It's a trick, naturally.. MS only enumerate the dir youre looking at, and place dummy nodes as children at every node. That's why every node seems expandable, but some arent; when you try to expand it, the OS looks and find no children and simply removes the dummy node, causing the + to disappear

(Actually, later versions of windows did fix this in that they check each folder for the presence of subdirectories.. but that means they are ONLY enumerating one level deeper than where youre currently looking. They are NOT enumerating an entire drive)

You can try a component called Raccoom TreeViewFolderFolderBrowser as a starting point for an Explorer-aware, checkbox enabled treeview for folders
 
Erm. You seem to be worried that every other manufacturer out there actually enumerates ALL folders before showing the tree, and knows some trick to make the whole of C: enumerate instantly, that you dont..

How about Microsoft.. in old versions of explorer.. did you ever notice that when youre using folders view, you expand it and EVERY folder has a + sign next to it? EVEN THOSE WITH NO SUBFOLDERS?

It's a trick, naturally.. MS only enumerate the dir youre looking at, and place dummy nodes as children at every node. That's why every node seems expandable, but some arent; when you try to expand it, the OS looks and find no children and simply removes the dummy node, causing the + to disappear

(Actually, later versions of windows did fix this in that they check each folder for the presence of subdirectories.. but that means they are ONLY enumerating one level deeper than where youre currently looking. They are NOT enumerating an entire drive)

You can try a component called Raccoom TreeViewFolderFolderBrowser as a starting point for an Explorer-aware, checkbox enabled treeview for folders

You are indeed right, that is what I thought but then went with the suggestion above.

I've now got it showing all drives within milliseconds and it's built when the node is clicked. It's instant and works fine.

I'll mark this as fixed.

Edit: Erm, however I do that.
 
Back
Top