Results 1 to 15 of 15

Thread: Searching hdd for mp3 files

  1. #1

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Searching hdd for mp3 files

    Hey,

    I have a simple program and was wondering how I would be able to search my hard drive for mp3 files and store their path names in an XML file?

    Thanks, Andy
    Living a Lie, Timmy

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Searching hdd for mp3 files

    Check out this thread in the codebank about recursive filesearching...

    http://www.vbforums.com/showthread.php?t=341919

  3. #3

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Searching hdd for mp3 files

    Thanks for the link mate.

    do you know how i could use this code?

    I just want a text box and a search button that returns the results in a list or preferably in an xml file.

    Thanks, Andy
    Living a Lie, Timmy

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Searching hdd for mp3 files

    Post number 8 in that link has everything, the class as well as usage. Just paste the code into a new Class, then the usage shows how you use it. The results are stored in a Files arraylist...

  5. #5

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Searching hdd for mp3 files

    How would I be able to call the class when a command button is clicked and display the results?
    Living a Lie, Timmy

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Searching hdd for mp3 files

    Thats what the "usage" section is for on that post..... shows how to use the class...
    Code:
            Dim x As New FileSearch()
            x.Search("d:\Media\", "*.jpg;*.jpeg")
            MessageBox.Show(x.Files.Count) ' number of files that match "*.jpg" and "*.jpeg" in D:\Media\Pictures
            MessageBox.Show(x.Directories.Count) ' the total number of directories looked through
    x.Files is an arraylist, so one thing you can use is the addrange method of a listbox to show all the files, as in....
    VB Code:
    1. ListBox1.Items.AddRange(x.Files.ToArray)
    Last edited by gigemboy; Feb 6th, 2006 at 06:07 PM.

  7. #7

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Searching hdd for mp3 files

    Briliant!

    Sorry I am just learning this and haven't programmed in 3 years so my logical thinking has gone right out the window.

    When my button (cmdSearch) is clicked it displays the message box sucessfully now but the listview isnt displaying the results though.

    I have the following code in my ListView1:
    VB Code:
    1. ListBox1.Items.AddRange(x.Files.ToArray)
    Living a Lie, Timmy

  8. #8
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Searching hdd for mp3 files

    You had mentioned ListView1, that is a listview. I had specified a way to do it using a Listbox, not a listview

  9. #9

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Searching hdd for mp3 files

    Sorry that was a typo it is a listbox?!?
    Living a Lie, Timmy

  10. #10
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Searching hdd for mp3 files

    If you are searching you entire hard drive, it will probably take a while. I tested the code in one directory that had jpg's, and it worked fine. You didn't mention if you got a positive value in the messagebox?

  11. #11

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Searching hdd for mp3 files

    Yes the numbers do seem to add correctly!
    Living a Lie, Timmy

  12. #12
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Searching hdd for mp3 files

    Are you sure you are adding it to the correct listbox? lol ... dont know what else to tell you, as it worked perfectly for me...

  13. #13

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Searching hdd for mp3 files

    Got it sorted. Cheers for the help, was being stupid!
    Living a Lie, Timmy

  14. #14
    Member alistair4267's Avatar
    Join Date
    Jul 2001
    Posts
    45

    Question Re: Searching hdd for mp3 files using LISTVIEW

    hi all

    ok, you have talked about using a Listbox to get the contents of a folder and displaying the results. but what if i wanted to used a LISTVIEW control in order to show

    Artist | trackname | year

    how would i do that, am i right in thinking IDV3 tags are used to do this ????

    thank alistair

    oh by the way the code works for me

  15. #15
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Searching hdd for mp3 files

    Well, you would have to create an array of listviewitems using the results in the arraylist (or loop through the arraylist, adding each listviewitem you create individually to the listview),then use the .AddRange method of the ListView class in order to add the items (or .Add if adding them individually). You have to create a listviewitem, and then add the listviewitem to the listview. Plus you have SubItems of each Item that you would need to set, etc. Just read up on the ListView Class, it is a little more in depth that a regular listbox...

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