|
Función recursiva en un TreeView
Hey guys...somewhere I found a very good and effective algorithm you are trying I guess...
procedure DirectoryTree(Tree:TTreeView;Memo1:TMemo ; RootDirectory:string);
var
sr: TSearchRec;
FileAttrs: Integer;
theRootNode : tTreeNode;
theNode : tTreeNode;
procedure AddDirectories(theNode: tTreeNode; cPath: string);
var
sr: TSearchRec;
FileAttrs: Integer;
theNewNode : tTreeNode;
begin
FileAttrs := faAnyFile; //TSearchRec constant
if FindFirst(cPath+'\*.*', FileAttrs, sr) = 0 then
begin
repeat
if ((sr.Attr and FileAttrs) = sr.Attr) and (copy(sr.Name,1,1) <> '.')
then
begin
theNewNode := Tree.Items.AddChild(theNode,sr.name);
AddDirectories(theNewNode,cPath+'\'+sr.Name);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
begin
FileAttrs := faAnyFile; //TSearchRec constant
theRootNode := Tree.Items.AddFirst(nil,RootDirectory);
if FindFirst(RootDirectory+'*.*', FileAttrs, sr) = 0 then
begin
theNode := Tree.Items.GetFirstNode;
AddDirectories(theNode,RootDirectory+sr.Name);
FindClose(sr);
end;
end;
|