recursive error with IdFTP.DirectoryListing ?

recursive error with IdFTP.DirectoryListing ?

Post by Thorsten J » Tue, 04 May 2004 21:25:46


Hello NG

i have a problem with a recursive function.
after getting one level back from the recursive function in the for-loop
the variable myList has the content of level deeper.
Where is my fault ?


procedure ReadFTPsubDir(rootDir, dirpath: string);
var
connectTest : boolean;
dir_list : TStringList;

i : integer;

myList : TIdFTPListItems;
myItem : TIdFTPListItem;
itemCounts : integer;
begin
connectTest := TRUE;

try
IdFTP1.ChangeDir(rootDir);
except
on E: Exception do
begin
l_connectedhost.Caption := E.Message;
connectTest := FALSE;
end;
end;

if connectTest then
begin
dir_list := TStringList.Create;
try
IdFTP1.List(dir_list);
finally
myList := IdFTP1.DirectoryListing;
itemCounts := myList.Count - 1;

for i := 0 to itemCounts do
begin
myItem := myList.Items[i];
if myItem.ItemType = ditDirectory then
begin
lb_host_dirs.Items.Add(dirpath + myItem.FileName);
ReadFTPsubDir(myItem.FileName + '/', dirpath +
myItem.FileName + '/');
end;
end;
end;

dir_list.Free;
end;
end;