Determining directory contents quickly

  • Thread starter Thread starter Pete Davis
  • Start date Start date
P

Pete Davis

I'm implementing a folder browser style control in a tree view.

Windows Explorer, when it comes up with a tree view, almost immediately,
knows if folders contain other folders or not (unless it's a networked
drive).

How does it accomplish this? Obviously doing Directory.GetDirectories() for
each subdirectory is not going to give me that sort of immediate response.

Pete
 
Yes, beyodn trying, I've actually got it written and I'm dissatisified with
the performance, which is why I'm now asking here. It's particularly
affected by the number of subdirectories. So if I do a
Directory.GetDirectories() on a folder that has say, 1000 sub directories,
it's going to be far slower, which makes sense.

Pete
 
Make sure that GetDirectories() is the culprit. Try calling it on a large
folder without displaying anything and time it.

My first bet would be the treeview.
Try suspending layout when adding items:
treeView1.SuspendLayout();
.... add stuff
treeView1.ResumeLayout();

Also try adding the items to the tree using AddRange().

Oh, and obviously don't forget to NOT populate the whole tree at once
recursively.
 
Ah, SuspendLayout did make a big difference. For very large directories,
there's a bit of a period where it blanks out, but it's still far faster
than before. Definitely acceptable.

And yes, I'm not populating the entire tree at once. Just a level at a time
as branches are expanded.

Thanks.

Pete
 
Back
Top