Ahora sí, mejor imposible!, aquí tienen la forma más eficiente:
Private Function Get_Files(ByVal rootDirectory As String, ByVal recursive As Boolean, ParamArray exts() As String) As List(Of IO.FileInfo)
Dim searchOpt As IO.SearchOption = If(recursive, IO.SearchOption.AllDirectories, IO.SearchOption.TopDirectoryOnly)
Return IO.Directory.GetFiles(rootDirectory, "*.*", searchOpt).Where(Function(o) exts.Contains(IO.Path.GetExtension(o))).Select(Function(p) New IO.FileInfo(p)).ToList
End Function
Ejemplo de uso:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each file In Get_Files
("C:\Windows",
True,
{".dll",
"DLL"}) :
MsgBox(file.
Name) :
Next End Sub
EDITO: Lo único imperfecto es que no es
Ignore case, así que habría que usar la función así:
For Each file In Get_Files
("C:\Windows",
True,
{".dll",
"DLL"}) :
MsgBox(file.
Name) :
Next