|
-
Apr 17th, 2003, 01:54 PM
#1
Thread Starter
Addicted Member
Load Files into listbox
Hey.
how can you load files into a list box.
Say i have a folder C:\Files and i want to add ONLY the .mp3 file names into a listbox how would i do this?
Thanks
-
Apr 17th, 2003, 01:58 PM
#2
Member
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' make a reference to a directory
Dim di As New IO.DirectoryInfo("c:\")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Sub
To get only .mp3 files change di.GetFiles() to di.GetFiles(.mp3).
(I think)
That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.
-
Apr 17th, 2003, 04:11 PM
#3
Fanatic Member
Almost, it's
Code:
di.GetFiles("*.mp3")
and to add to the listbox you probably only want the filename, so it would be
Code:
ListBox1.Items.Add(dra.Name)
-
Apr 17th, 2003, 04:18 PM
#4
Thread Starter
Addicted Member
thx alot..
Hey it works great thanks all~!
-
Apr 17th, 2003, 04:40 PM
#5
I wonder how many charact
Or to be brief about it, and, lose the performance hit of a for-next, and, lose the resources caused by declaring the FileInfo and other class instance:
VB Code:
Dim di As New System.IO.DirectoryInfo("[b]C:\Documents and Settings\You\My Documents\My Music[/b]")
ListBox1.Items.AddRange(di.GetFiles("*.mp3"))
those are the only two lines you need... just make sure to change the path highlighted in bold or you'll
get a path not found error.
Last edited by nemaroller; Apr 17th, 2003 at 04:48 PM.
-
Apr 17th, 2003, 05:36 PM
#6
Fanatic Member
Yeah that's a much better way to do it.
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
|