Results 1 to 5 of 5

Thread: Is there a way to show the filenames of multiple folders in a listbox?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Is there a way to show the filenames of multiple folders in a listbox?

    Hi there folks! I am working on a program where in 1 listbox there are a bunch of folder pathways. In a second listbox, I would like to display the file names of all of the folders listed in the first listbox. For example, there might be 5 folders listed in listbox 1, I would like listbox2 to show all of the filenames of those folders from listbox1.

    Now if there was a way to take those pathways, and list the contents of each in the first listbox, that would be good too, but right now, I have the pathways listed in listbox 1, would anyone know how to list the contents of each path in a second listbox?

    Thanks a lot!

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Is there a way to show the filenames of multiple folders in a listbox?

    Yes you can, though you probably should have posted this in the other thread you started.

    You can use DIR$() in a loop to get the folder contents and then add them to the list box as desired.
    Optionally you can use a file list box, set the path, pull the list items from that to your list then move on to the next path and repeat.
    There are also other options such as API and FSO

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to show the filenames of multiple folders in a listbox?

    Ok, thanks for the idea. I am going to try to copy the filelistbox first.

    So I tried out this..

    Dim i As Long
    For i = 1 To ListOfFilenames.ListCount

    TotalFileNamesList.AddItem (ListOfFilenames.List(i))
    Next

    . Now this code doesn;t give me any errors, but it also leaves the TotalFileNames listbox blank. Given for this example, I only have one filename in the pathway used in the ListofFileNames listbox, but that wouldn't be why the TotalFileNames would come up blank right?

    EDIT, actually I decided to go with DIR, and it works great!

    So I found this snippet of code, and it works great.
    VB Code:
    1. Private Sub ListFiles(strPath As String, Optional Extention As String)
    2. 'Leave Extention blank for all files
    3.     Dim File As String
    4.    
    5.     If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
    6.    
    7.     If Trim$(Extention) = "" Then
    8.         Extention = "*.*"
    9.     ElseIf Left$(Extention, 2) <> "*." Then
    10.         Extention = "*." & Extention
    11.     End If
    12.    
    13.     File = Dir$(strPath & Extention)
    14.     Do While Len(File)
    15.         TotalFileNamesList.AddItem File
    16.         File = Dir$
    17.     Loop
    18. End Sub
    19.  
    20. 'This code will call the above sub
    21. ListFiles ListOfFilenames.Path, "mp3"
    \
    I guess my question is now that I can get the filename for one folder put in the TotalFileName Listbox, if the listbox that contains the pathways has 5 10 or even 20 pathways, how could I loop the above code to go through each pathway in the Pathwaylistbox


    2nd edit: I realize when I changed the approach from filelistbox to DIR, I kept the filelistbox and used its path for the DIR, should I have used the PathwayListbox index?
    Thanks!
    Last edited by Justin M; Jul 10th, 2017 at 12:39 PM.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Is there a way to show the filenames of multiple folders in a listbox?

    You would just need to add a loop calling the routine that adds the folder content to the list passing each path from your list of paths as it loops.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to show the filenames of multiple folders in a listbox?

    Ok, I think........ this is working for me I just tried two paths and it worked on that...

    VB Code:
    1. Dim i As Long
    2.  
    3.     For i = 0 To UsingList.ListCount - 1    'loop through the items in the ListBox
    4.         If UsingList.Selected(i) = True Then    ' if the item is selected(checked)
    5.             MasterList.AddItem App.Path & "\ResourceFiles\MP3Files\" & UsingList.List(i) & "\"        ' display the item
    6.             ListOfFilenames.Path = App.Path & "\ResourceFiles\MP3Files\" & UsingList.List(i) & "\"
    7.             ListFiles ListOfFilenames.Path, "mp3"
    8.         End If
    9.     Next

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