Click here to Skip to main content
15,904,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guy am having a little problem:
my goal is to get all file with an mp3 extension listed on a listbox in vb
in that case the location of that directory in c:\Users\%Username%\music

I have this code but it's not working:
VB
Dim di As New IO.DirectoryInfo("C:\Users\%userprofile%\Music")
        Dim diar1 As IO.FileInfo() = di.GetFiles()
       Dim dra As IO.FileInfo
       
        For Each dra In diar1
       ListBox1.Items.Add(dra)
       Next

please help me
Posted
Updated 4-Jan-13 17:42pm
v2
Comments
Sandeep Mewara 4-Jan-13 23:44pm    
Can you elaborate 'not working' and our observations when you debugged it?

Try the following:
VB
For Each dra In diar1
ListBox1.Items.Add(dra.Name) ' or dra.FullName
Next
 
Share this answer
 
For such a simple thing, use System.IO.Directory instead. I don't know what to explain here; everything is written: http://msdn.microsoft.com/en-us/library/system.io.directory.aspx[^].

Oh no, sorry, not everything. There is one unpleasant subliminal Microsoft problem about it. Please see:
Directory.Get.Files search pattern problem[^].

First, I learned about it from CodeProject members! Highly appreciate the lesson.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900