Re: FTP DirectoryListing question

Giganews Newsgroups
Subject: Re: FTP DirectoryListing question
Posted by:  Remy Lebeau (TeamB) (gambit47.no.spam@no.spam.yahoo.com)
Date: Tue, 18 Nov 2003

"eshipman" <eshipman@yahoo!!!.com> wrote in message
news:MPG.1a240a1136ac56d39896…@news.atozedsoftware.com...

> This gives me an index out of bounds error:

At what point exactly?  Pleae be more specific.

If you want to know whether an item is a directory or not, use the
TIdFTPListItem::ItemType property instead.  Try this (untested):

    procedure FTPDirToTreeView(AUserName, APassword: String; AFTP: TidFTP;
ATree : TTreeView; ADirectory : string; AItem : TTreeNode; AIncludeFiles :
Boolean);
    var
        ItemTemp : TTreeNode;
        i : integer;
        DirList: TIdFTPListItems;
        DirItem: TIdFTPListItem;
    begin
        ATree.Items.BeginUpdate;
        try
            if (ADirectory <> '') then AFTP.ChangeDir(ADirectory);
            AFTP.TransferType := ftASCII;
            AFTP.List(nil);

            DirList := AFTP.DirectoryListing;
            for i := 0 to DirList.Count - 1 do
            begin
                try
                    DirItem := DirList.Items[i];
                    if (DirItem.ItemType = ditDirectory) then // This is
Directory
                    begin
                        AItem := ATree.Items.AddChild(AItem,
Trim(DirItem.FileName) + '/');
                        ItemTemp := AItem.Parent;
                        FTPDirToTreeView(AFTP, ATree,  ADirectory +
Trim(DirItem.FileName) + '/', AItem, AIncludeFiles);
                        AItem := ItemTemp;
                    end
                    else
                    begin
                        if (AIncludeFiles) then ATree.Items.AddChild(AItem,
DirItem.FileName);
                    end;
                except
                end;
            end;
        finally
            ATree.Items.EndUpdate;
        end;
    end;

Gambit

Replies

In response to

FTP DirectoryListing question posted by eshipman on Tue, 18 Nov 2003