Results 1 to 11 of 11

Thread: Building a TreeView/ListView similar to Windows Explorer for FTP application

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Building a TreeView/ListView similar to Windows Explorer for FTP application

    I'm currently working on an FTP client which I have it working with all the trimmings.

    What I would like to add to it is to show the directories of the site in a tree view control and the contents of a directory in the list view control. I want it to work just like Windows Explorer works.

    OK, not knowing how I would go about doing this using APIs I manually built a text file that has every directory and sub directories. I load this text file from the hdd and build the tree view listing from it. Works!

    I already know how to get the contents of any directory and display them in the list view.

    What I don't know is how can I build the tree view directory listings without using this text file but instead using APIs if there are any. This would have to build the complete tree view before any directory is clicked on


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,708

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    Do you mean just for the remote site or you want to display local contents on one side and FTP on the other?

    APIs for what, reading FTP directories or making a TreeView/ListView?
    Last edited by fafalone; Aug 15th, 2015 at 01:50 PM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    Well, I already have an explorer VB project that works and the download vbexplorer.zip is a nice project as well for explorer on your local disk drive but really serves no purpose to me.

    You see I already have an explorer window for my FTP project which works exactly the way I like it very much like Window's Explorer. What I don't have the the means to get the directories/subdirectories off the web site unless I use my pre-built text file which lists all of them but I want to get out of using that and dynamically generate a list of all folders
    Last edited by jmsrickland; Aug 15th, 2015 at 02:25 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,708

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    So the real question is how do you list directories and files on an FTP site. You've got to be sending FTP commands and receiving responses already, is there a problem with the normal LS command?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    No, the question is not how do you list directories and files on an FTP site, that I know.

    The question is how do I start with the very 1st directory and from there parse through it looking for all the subdirectories and continueing on with this until I have gone through every directory and every subdirectory of every directory and put this all together creating a tree view of the directory structures. I though I explained this in my 1st post.

    Seems like you totally changed your post #2. Why
    Last edited by jmsrickland; Aug 16th, 2015 at 01:04 AM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    i seem to remember a similar thread started by you in 2011
    http://www.vbforums.com/showthread.p...emote-computer

    most of your questions should already be answered in that or the codebank thread that i posted after
    http://www.vbforums.com/showthread.p...light=ftp+tree

    i posted examples using both a shell object and APIs
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    2011 Good grief, westconn, I can't even remember last month

    OK, I'll check out the links you posted. Thanks


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,708

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    Quote Originally Posted by jmsrickland View Post
    No, the question is not how do you list directories and files on an FTP site, that I know.

    The question is how do I start with the very 1st directory and from there parse through it looking for all the subdirectories and continueing on with this until I have gone through every directory and every subdirectory of every directory and put this all together creating a tree view of the directory structures. I though I explained this in my 1st post.

    Seems like you totally changed your post #2. Why
    I changed it because I realized you were talking about listing the remote directories, not local ones, and could already add them to the TV/LV once you had them. My original comment only applied to listing local files.

    If your question isn't how to get a list of files and directories on an FTP site then no I don't understand the question. You list the top level after login, the recursively go through each directory returned (although every FTP client I've had doesn't pre-load like you seem to want to do). Top directory would be the original node on the TV, and each level would be the child of the last.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    Quote Originally Posted by fafalone View Post
    I changed it because I realized you were talking about listing the remote directories, not local ones, and could already add them to the TV/LV once you had them. My original comment only applied to listing local files.

    If your question isn't how to get a list of files and directories on an FTP site then no I don't understand the question. You list the top level after login, the recursively go through each directory returned (although every FTP client I've had doesn't pre-load like you seem to want to do). Top directory would be the original node on the TV, and each level would be the child of the last.
    OK, so now you seem to be getting what I am asking. So my question is how, not what do I do but how do I do it. How do I recursively go through each directory? That's what I don't know how to do.

    What do you mean doesn't pre-load like you seem to want to do

    I know when you open up your initial directory that's all you get. I know that within that directory there are other sub directories and within those sub directories even more sub directories, etc, etc.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    @westconn

    Two problems with your last addition

    You have the following code

    Code:
    Private Sub tv_NodeClick(ByVal Node As MSComctlLib.Node)
     If Node.Children > 0 Then Node.Expanded = True: Exit Sub
              
     If Right(Node.Key, 1) = pathsep Then
       listdirs sh.NameSpace(Node.Key), Node
     Else
       MsgBox "this is a file " & Node.Key
     End If
              
     Node.Expanded = True
    End Sub
    1)
    Here you check if directory name (which was clicked on in the treeview) has a "/" on the end of the line:

    If Right(Node.Key, 1) = pathsep

    However, shouldn't everything be a directory name since the treeview only contains directory names and the name was clicked on as a treeview node. So why the check? Also, the names do not end with a "/" so control goes to the Else clause which is incorrect.

    2)
    In the 1st If clause you have this:

    listdirs sh.NameSpace(Node.Key), Node

    but sh.NameSpace() causes error 91 object variable or With block not set. I see no where in the code where it is set.
    Am I supposed to set this to something?

    And yes, I added a reference to Microsoft Shell Controls and Automation

    EDIT: OK, I added this line in Form_Load():

    Set sh = CreateObject("shell.application")

    This appears to take care of the 2nd issue stated above. But now it creates another issue. When it calls:

    listdirs sh.NameSpace(Node.Key), Node but in sub listdirs:

    Sub listdirs(f As Object, nod As Object)

    f is always Nothing
    Last edited by jmsrickland; Aug 30th, 2015 at 12:13 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Building a TreeView/ListView similar to Windows Explorer for FTP application

    Here you check if directory name (which was clicked on in the treeview) has a "/" on the end of the line:

    If Right(Node.Key, 1) = pathsep

    However, shouldn't everything be a directory name since the treeview only contains directory names and the name was clicked on as a treeview node. So why the check? Also, the names do not end with a "/" so control goes to the Else clause which is incorrect.
    i had made some changes (on request), that can optionally be used to list all files as well as folders
    one part of change included ending the node keys for directories with pathsep
    this is in post #4 listdirs (and now below), same as the code posted directly above, it should make no difference whether or not you want to list the files
    i just modified the code to list all directories first then files, the files could then be listed in some other control

    Code:
        Sub listdirs(f As Object, nod As Object)
                  Dim nod2 As Object, fitem As Object, i As Integer
                  If f Is Nothing Then Exit Sub
                  ' list all folders first
                  For Each fitem In f.items
                      If fitem.isfolder Then Set nod2 = tv.Nodes.Add(nod, tvwChild, nod.Key & fitem.Name & pathsep, fitem.Name)
                      ' note the above adds pathsep to node key for folders
                  Next
                  For Each fitem In f.items
    
                        If Not fitem.isfolder Then tv.Nodes.Add nod, tvwChild, nod.Key & fitem.Name, fitem.Name
                        ' the above line can be replaced, to put the files into any other controls
                  Next
                  End Sub
    Last edited by westconn1; Aug 31st, 2015 at 05:32 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width