Get drives/directories

blindreaper666
09-24-2004, 04:42 PM
How can I get the names of all of the drives, folder, files and put them in a treeview, like in an explorer window? I was trying to put them into an array, but i'm not sure ho w to get the info on them all.

AtmaWeapon
09-24-2004, 05:02 PM
There's quite a few examples on the net, but I'll help you through the process.

The drive letters can be found by calling Environment.GetLogicalDrives, but if the documentation is correct it only works for hard drives. One of my books at home has a way to get the other drives, I can get to it in a few hours.

From the drive, it's a simple matter to get a DirectoryInfo object and use DirectoryInfo.GetDirectories to get the subdirectories of the current directory.

You probably do not want to get all directories and files and save them into an array. The last virus scan I ran went through about 175,000 files across 80,000 directories. That's a computer I've installed a lot on though. Even so, this office workstation that I've only installed MS Office and VS .NET on has more than 12,000 files in C:\Windows alone, and that's not counting the entries in its 885 subdirectories.

The workaround for this is when a user selects a visible directory, you fill in its subdirectories there. This is how Windows Explorer does it, and the book with the example finally explained to me why there was such a delay loading Windows Explorer and expanding large subfolders on many computers. I have a sample app that shows it in pretty full detail.

Faith
09-24-2004, 05:05 PM
If you want to easily escape of this problem, you should check Google for "FileView" control for .NET, there certainly are such available...

AtmaWeapon
09-24-2004, 05:44 PM
OK, code straight from the book. It actually catches floppy and CD drives, so I think the documentation is in error. Add all files (including the bitmaps) to a project, then make sure to set the "Build Action" property of the bitmap files to "Embedded Resource".

The FileView control may work, I've never heard of it or used it. Sometimes it's nice to know how things work internally, though :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum