light_bulb
asked on
Delphi FTP TreeView
How can I create a TreeView that displays all directories/files in a FTP site?
I'm using IdFTP for this. Here's the code I have now, but it's giving me an error when it gets to a subdirectory:
Procedure TForm1.FTPDirToTreeView(AFTP: TidFTP; ATree: TTreeView;
ADirectory: String; AItem: TTreeNode;
AIncludeFiles: Boolean);
Var
ItemTemp: TTreeNode;
LS: TStringList;
i: integer;
Begin
ATree.Items.BeginUpdate;
LS := TStringList.Create;
Try
If ADirectory <> '' Then
AFTP.ChangeDir(ADirectory);
AFTP.TransferType := ftASCII;
AFTP.List(LS);
If AFTP.DirectoryListing.Count <> 0 Then
Begin
For i := 0 To AFTP.DirectoryListing.Count - 1 Do
Begin
If AFTP.DirectoryListing.Items[i].ItemType = ditDirectory Then //Here's where I get an out of index error
Begin
AItem := ATree.Items.AddChild(AItem , AFTP.DirectoryListing.Items[i].FileName);
ItemTemp := AItem.Parent;
FTPDirToTreeView(AFTP, ATree, ADirectory + AFTP.DirectoryListing.Items[i].FileName, AItem, AIncludeFiles);
AItem := ItemTemp;
End
Else If (AIncludeFiles) Then //if not a directory
Begin
ATree.Items.AddChild(AItem , AFTP.DirectoryListing.Items[i].FileName);
End;
End;
End;
Finally
ATree.Items.EndUpdate;
LS.Free;
End;
End;
This lists all files until the first subdirectory, but then puts items from the subdirectory into the root directory. I also get an out of index error on the indicated line.
Thank for your help!
I'm using IdFTP for this. Here's the code I have now, but it's giving me an error when it gets to a subdirectory:
Procedure TForm1.FTPDirToTreeView(AFTP:
ADirectory: String; AItem: TTreeNode;
AIncludeFiles: Boolean);
Var
ItemTemp: TTreeNode;
LS: TStringList;
i: integer;
Begin
ATree.Items.BeginUpdate;
LS := TStringList.Create;
Try
If ADirectory <> '' Then
AFTP.ChangeDir(ADirectory);
AFTP.TransferType := ftASCII;
AFTP.List(LS);
If AFTP.DirectoryListing.Count <> 0 Then
Begin
For i := 0 To AFTP.DirectoryListing.Count - 1 Do
Begin
If AFTP.DirectoryListing.Items[i].ItemType = ditDirectory Then //Here's where I get an out of index error
Begin
AItem := ATree.Items.AddChild(AItem
ItemTemp := AItem.Parent;
FTPDirToTreeView(AFTP, ATree, ADirectory + AFTP.DirectoryListing.Items[i].FileName, AItem, AIncludeFiles);
AItem := ItemTemp;
End
Else If (AIncludeFiles) Then //if not a directory
Begin
ATree.Items.AddChild(AItem
End;
End;
End;
Finally
ATree.Items.EndUpdate;
LS.Free;
End;
End;
This lists all files until the first subdirectory, but then puts items from the subdirectory into the root directory. I also get an out of index error on the indicated line.
Thank for your help!
Oh crap, that sure looks like my code...
Looks like you are trying to combine the techniques. You can not do that.
Use one or the other. They both work but you can only use one approach.
Looks like you are trying to combine the techniques. You can not do that.
Use one or the other. They both work but you can only use one approach.
It also is dependent upon the way the server returns the file list.
They are not all the same, BTW...
They are not all the same, BTW...
ASKER
I'll have to look at it a little closer later....I'm leaving on vacation today. :)
I got your first method to work, but it shows the whole ftp description for each item including permissions, modify date, etc. I need it to just show the file/folder name.
Thanks,
I got your first method to work, but it shows the whole ftp description for each item including permissions, modify date, etc. I need it to just show the file/folder name.
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.delphipages.com/tips/thread.cfm?ID=210