Android smartphone

2009-10-12

How to show Directories in a TTreeview?

This tips comes from our partner SwissDelphiCenter.ch

mailto:info@delphitips.com

Author:
Gustav Evertsson
Ratings: 0, Votes: 0

procedure TForm1.GetDirectories(Tree: TTreeView; Directory: string; Item: TTreeNode; IncludeFiles: boolean);
var
SearchRec: TSearchRec;
ItemTemp: TTreeNode;
begin

Tree.Items.BeginUpdate;
if Directory[length(Directory)] <> '\' then Directory := Directory + '\';
if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then
begin
repeat
if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] <> '.')

then
begin
if (SearchRec.Attr and faDirectory > 0) then
Item := Tree.Items.AddChild(Item, SearchRec.Name);

ItemTemp := Item.Parent;
GetDirectories(Tree, Directory + SearchRec.Name, Item, IncludeFiles);
Item := ItemTemp;
end else

if IncludeFiles then
if SearchRec.Name[1] <> '.' then
Tree.Items.AddChild(Item, SearchRec.Name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
Tree.Items.EndUpdate;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GetDirectories(TreeView1, 'C:\', nil, True);
end;

No comments: