Results 1 to 5 of 5

Thread: [RESOLVED] [2005] List box read off folders

  1. #1

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Resolved [RESOLVED] [2005] List box read off folders

    i want my listbox to show every file of a certain file type in a specified folder (audio files to be more specific)

    how would i go about doing that?

    thnx
    Phil
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] List box read off folders

    I can't remember the format for the pattern searching so that bit is probably wrong but the code works perfectly. Just check out how to specify a search pattern:


    VB Code:
    1. Dim di As New IO.DirectoryInfo("Path here")
    2.         Dim diArr As IO.FileInfo() = di.GetFiles("*.mp3")  'This gets certain type. I can't remember the format though
    3.         For Each dri As IO.FileInfo In diArr
    4.             listbox1.Items.Add(dri.Name)  'Add to listbox
    5.         Next dri
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: [2005] List box read off folders

    sweet it works! thanks a bunch. is there a way so that it doesn't show the extension (.mp3)?
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] List box read off folders

    You can either process the items in the list and remove the extension or you can check out the:

    IO.Path.GetFileNameWithoutExtension(String)

    Method. The above code I posted wont work as is with this method however due to the new method using a string to function.

    VB Code:
    1. Dim tmp As String = "D:\My Documents\"
    2.         Dim Files() As String
    3.         Files = System.IO.Directory.GetFiles(tmp, "*.mp3")
    4.         For Each str As String In Files
    5.             ListBox1.Items.Add(IO.Path.GetFileNameWithoutExtension(str))
    6.         Next
    Last edited by stimbo; Jan 27th, 2007 at 01:20 PM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: [2005] List box read off folders

    kickass thanks a bunch
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width