procedure TForm1.AddTree(Path : string; ParentNode: TTreeNode);
var
SearchRec : TSearchRec;
IFound : integer;
newnode : TTreeNode;
begin
IFound := FindFirst(Path + '/*.*', faAnyFile, SearchRec);
While IFound = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
if SearchRec.Attr = faDirectory then
begin
newnode := TreeView1.Items.AddChild(ParentNode, SearchRec.Name);
AddTree(Path + '/' + SearchRec.Name, newnode);
end
else
TreeView1.Items.AddChild(ParentNode, SearchRec.name);
end;
IFound := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddTree('C:', nil);
end;
var
SearchRec : TSearchRec;
IFound : integer;
newnode : TTreeNode;
begin
IFound := FindFirst(Path + '/*.*', faAnyFile, SearchRec);
While IFound = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
if SearchRec.Attr = faDirectory then
begin
newnode := TreeView1.Items.AddChild(ParentNode, SearchRec.Name);
AddTree(Path + '/' + SearchRec.Name, newnode);
end
else
TreeView1.Items.AddChild(ParentNode, SearchRec.name);
end;
IFound := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddTree('C:', nil);
end;