[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delphi FTP TreeView

Posted on 2006-05-04
7
Medium Priority
?
1,105 Views
Last Modified: 2011-11-28
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!

0
Comment
Question by:light_bulb
  • 4
5 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 16617848
See my article here, it shows two ways with Indy's idFTP:
http://www.delphipages.com/tips/thread.cfm?ID=210
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 16617902
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.

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 16617906
It also is dependent upon the way the server returns the file list.
They are not all the same, BTW...
0
 
LVL 3

Author Comment

by:light_bulb
ID: 16619274
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,
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 1000 total points
ID: 16619688
Then you are going to have to parse the listings. That is what the DirectoryListing property does for you.
Use the second method alone and it should also work for you.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question