My.Computer.FileSystem.GetFiles Variable ?

CdRsKuLL

Active member
Joined
Sep 26, 2006
Messages
40
Programming Experience
Beginner
Hi, I'm hoping someone can help me. I'm trying to use the following code but also include a variable..

Works...
Dim files As ObjectModel.ReadOnlyCollection(Of String) = _
My.Computer.FileSystem.GetFiles(drivepath,
FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")

Does't work
Dim Musicfiletypes as string = "*.mp3"
Dim files As ObjectModel.ReadOnlyCollection(Of String) = _
My.Computer.FileSystem.GetFiles(drivepath,
FileIO.SearchOption.SearchTopLevelOnly, Musicfiletypes)

I'm sure it's an easy fix.. I actually want to use the multifile option ie.. "*.mp3","*.avi" etc..

thanks

Steve
 
mm that's really weird, it should work? maybe you have code elsewhere that is throwing the error? i tried both versions and they work fine for me...

as for the multiple search patterns, it takes a string array so just pass in an array of the patterns you want to search for.


Ex:

        Dim path As String = "F:\Movies\New folder\"
        Dim searchPattern As String() = {"*.mkv", "*.avi", "*.mp4"}
        Dim files As ObjectModel.ReadOnlyCollection(Of String) = _
                    My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, searchPattern)
 
Many thanks FB.. got it sussed. I hadn't set my string as an array so was passing everything :-(

Again thanks for the example as well, much appreciated.. learning all the time.

Steve
 
I hadn't set my string as an array so was passing everything :-(
Passing one or more single String variables to that method is also ok, because the parameter is declared ParamArray.
 
Back
Top