Anyone out there know how to load the file contents of a directory into a list box? I also need the files to be restricted to one or two extensions (.gif and .jpg)
Thanks
ADrift
Printable View
Anyone out there know how to load the file contents of a directory into a list box? I also need the files to be restricted to one or two extensions (.gif and .jpg)
Thanks
ADrift
You need to use the "Dir" command.
Something like that.... just off the top of my head ;)Code:sNext = Dir("C:\Program Files",vbNormal)
Do while sNext <> ""
If InStr("|.gif|.jpg|", "|" & LCase$(Mid$(sNext,InStrRev(sNext,".")))) > 0 Then
ListBox.AddItem sNext
End If
sNext = Dir
Loop
That didn't work;
The listbox just came up empty,although the code did execute properly.
Any Other Ideas?
Thanks
Ari
Why not use the FileListBox control - you can set the pattern property of that to "*.jpg;*.gif", and set the path of it to wherever you want it to look.
Otherwise it behaves pretty much like a normal listbox.
The reason it came up empty is because you may have nothing in the directory. Or you forgot the \ .
It works fine for me. Good code Gen-X :rolleyes:.Code:sNext = Dir("C:\My Documents\",vbNormal)
Do while sNext <> ""
If InStr("|.gif|.jpg|", "|" & LCase$(Mid$(sNext,InStrRev(sNext,".")))) > 0 Then
ListBox.AddItem sNext
End If
sNext = Dir
Loop