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!
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
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:
Private Sub ListFiles(strPath As String, Optional Extention As String)
'Leave Extention blank for all files
Dim File As String
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
If Trim$(Extention) = "" Then
Extention = "*.*"
ElseIf Left$(Extention, 2) <> "*." Then
Extention = "*." & Extention
End If
File = Dir$(strPath & Extention)
Do While Len(File)
TotalFileNamesList.AddItem File
File = Dir$
Loop
End Sub
'This code will call the above sub
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!
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.
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:
Dim i As Long
For i = 0 To UsingList.ListCount - 1 'loop through the items in the ListBox
If UsingList.Selected(i) = True Then ' if the item is selected(checked)
MasterList.AddItem App.Path & "\ResourceFiles\MP3Files\" & UsingList.List(i) & "\" ' display the item
ListOfFilenames.Path = App.Path & "\ResourceFiles\MP3Files\" & UsingList.List(i) & "\"
ListFiles ListOfFilenames.Path, "mp3"
End If
Next