Results 1 to 3 of 3

Thread: Directory.GetFiles - how to use multiple file filters?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    32

    Directory.GetFiles - how to use multiple file filters?

    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.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    use the ;

    *.mp3;*.wma
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    32
    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.

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