Folder Tree (VB)

Reapz

Well-known member
Joined
Dec 15, 2002
Messages
74
Ive used treeviews before and have managed to get my head around them ok but this is the first time I have used one to list drives and folders like Windows Explorer (Dont need to worry about files btw). Anyway, Ive encountered a couple of problems.

1) I have had to eliminate drives that Arent ready. ie: empty floppy and optical drives otherwise trying to expand generates and error. I did this by simply ommitting drives that had no label. What I would like is to be able to handle empty drives properly like explorer does.

2) Regardless of the folder settings in Windows Explorer GetDirectories picks up system folders and adds them to the treeview and trying to expand these generates an Access denied error. Is it possible to make my App adhere to the windows folder settings?

Cheers!
 
1) You populate your treeview with the drives, not the folders within them. You should only attempt to get the list of folders within when the user actually clicks on them, like explorer does.

2) You need to examine the attributes of each folder as you process it, and simply dont show ones with the System or Hidden attributes.
 
Ok I thought I had this working doing what you said but it only seems to work with files. The only attribute that is returned when I do folder.Attributes is Directory. It doesnt mention whether it is a System or Hidden folder. So pulling out system and hidden files is simple but the system folders remain in the treeview.
 
Last edited by a moderator:
C#:
di = new System.IO.DirectoryInfo(path);
if ((di.Attributes & System.IO.FileAttributes.System) != System.IO.FileAttributes.System)
	System.Diagnostics.Debug.WriteLine(path);
 
Back
Top