Author: Tomas Rutkauskas
How can I insert a hierarchy drive in a TTreeView? I would liket to insert for
example my drive C:\ in the treeview.
Answer:
1 2 procedure FilePathToTreeNode(aTreeView: TTreeView; aRoot: TTreeNode;
3 Path: string; Recurse: boolean);
4 var5 NewNode: TTreeNode;
6 SRec: TSearchRec;
7 begin8 if FindFirst(Path + '*.*', SysUtils.faAnyFile, SRec) = 0 then9 repeat10 if (sRec.Name = '.') or (sRec.Name = '..') then11 Continue;
12 NewNode := aTreeView.Items.AddChild(aRoot, SRec.Name);
13 if Recurse and ((srec.Attr and sysutils.faDirectory) <> 0) then14 FilePathToTreeNode(aTreeView, NewNode, Path + srec.name + '\', True);
15 until16 FindNext(SRec) <> 0;
17 end;
18 19 //Call it like this:20 21 FilePathToTreeNode(TreeView1, nil, 'c:\', True);
Consider using ShellTreeView and ShellListView from the samples component page (at least in D6).