PDA

Click to See Complete Forum and Search --> : Directory.GetFiles - how to use multiple file filters?


nzmike
Aug 7th, 2002, 11:49 PM
Hi all...

I'm writing a very simple MP3 player as a learning exercise in various .Net technologies. The app allows the user to enter a directory name containing the audio files they want to load. I also allow the user to specify one or both of "*.mp3" or "*.wma" as the file extensions... but I can't work out how to return matching files without using the FileOpen dialog which I want to avoid.

eg: What I have now is...

dir = "F:\mp3\test"
filter = "*.mp3|*.wma"
Dim foundFiles As String()
foundFiles = Directory.GetFiles(dir, filter)

If the user selects only MP3 **OR** WMA then it works fine but if they select both (so the filter = "*.mp3|*.wma" as above) it returns nothing since the filter obviously matches no files.

So my Q is how can I get the filesystem to return me a list of files that match a filter containing multiple file types without using the FileOpen dialog?

TIA...

Mike.
:confused:

Cander
Aug 8th, 2002, 09:21 AM
use the ;

*.mp3;*.wma

nzmike
Aug 8th, 2002, 08:14 PM
Cander,

Thanks for that - however I should have mentioned I already tried that - the problem is that GetFiles doesn't appear to support mutiple extensions in the filter parameter at all and so I'm looking to see if there's another method to do this.

I know I can have an array of filters and do something like this:

For Each strFilter in arrFilters 'eg: *.mp3, *.wma etc
arrFoundFiles = Directory.GetFiles(currentdir, strFilter))
For Each strFileName in arrFoundFiles
'add filename to listbox (or whatever)...
Next
Next

The problem is that doing this takes forever in VB.Net when you have a lot of files to search (I've got 12GB worth of MP3's and WMA's!). Strangely enough writing it in C# runs loads faster but just for now I want to get it working in VB.Net... so I'm just looking for a better way to match files when multiple filters are specified and am hoping that the framework has an appropriate function.

Mike.