|
-
Oct 8th, 2000, 11:28 PM
#1
Thread Starter
New Member
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
-
Oct 9th, 2000, 12:03 AM
#2
Hyperactive Member
You need to use the "Dir" command.
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
Something like that.... just off the top of my head
-
Oct 9th, 2000, 07:58 AM
#3
Thread Starter
New Member
That didn't work;
The listbox just came up empty,although the code did execute properly.
Any Other Ideas?
Thanks
Ari
-
Oct 9th, 2000, 08:10 AM
#4
Frenzied Member
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.
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Oct 9th, 2000, 11:26 AM
#5
The reason it came up empty is because you may have nothing in the directory. Or you forgot the \ .
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
It works fine for me. Good code Gen-X .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|