|
-
Feb 6th, 2006, 06:11 AM
#1
Thread Starter
Addicted Member
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
-
Feb 6th, 2006, 06:22 AM
#2
Re: Searching hdd for mp3 files
Check out this thread in the codebank about recursive filesearching...
http://www.vbforums.com/showthread.php?t=341919
-
Feb 6th, 2006, 10:43 AM
#3
Thread Starter
Addicted Member
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
-
Feb 6th, 2006, 02:37 PM
#4
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...
-
Feb 6th, 2006, 04:43 PM
#5
Thread Starter
Addicted Member
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?
-
Feb 6th, 2006, 04:53 PM
#6
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:
ListBox1.Items.AddRange(x.Files.ToArray)
Last edited by gigemboy; Feb 6th, 2006 at 06:07 PM.
-
Feb 6th, 2006, 05:19 PM
#7
Thread Starter
Addicted Member
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:
ListBox1.Items.AddRange(x.Files.ToArray)
-
Feb 6th, 2006, 05:35 PM
#8
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
-
Feb 6th, 2006, 05:51 PM
#9
Thread Starter
Addicted Member
Re: Searching hdd for mp3 files
Sorry that was a typo it is a listbox?!?
-
Feb 6th, 2006, 06:06 PM
#10
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?
-
Feb 6th, 2006, 08:06 PM
#11
Thread Starter
Addicted Member
Re: Searching hdd for mp3 files
Yes the numbers do seem to add correctly!
-
Feb 6th, 2006, 08:23 PM
#12
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...
-
Feb 6th, 2006, 09:20 PM
#13
Thread Starter
Addicted Member
Re: Searching hdd for mp3 files
Got it sorted. Cheers for the help, was being stupid!
-
Feb 8th, 2006, 06:33 AM
#14
-
Feb 8th, 2006, 02:25 PM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|