VB.net help -- multiple file types in .GetFiles

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
Right now I have the following code:

Code:
Dim di As New DirectoryInfo(SourceFolderPath.Text)
Dim Filter = "*.pdf"
Dim fiArr As FileInfo() = di.GetFiles(Filter)

but I'd like to apply more "filters" so I can pull up more than just .pdf files.
Suggestions?

Thanks in advance.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
My initial theory was to
Filter = "*.pdf | *.doc | *.txt"

Try it
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Wrap another class around what you have
Pass in the filter
Parse the filter; make the GetFiles call; append the output into an array
Get the next filter and repeat.

At the end; you will have accomplished what you need and you have an array of file names containing the outputs.
 

0___________0

Senior member
May 5, 2012
284
0
0
I couldn't write VB to save my life, but you can get all of the files, then use Where to select the ones you want based on extensions. They aren't being filtered when you first index them, you're just keeping whichever ones match your list of extensions.

2nd or 3rd post: http://www.vbforums.com/showthread.php?664831-Multiple-file-extensions-with-GetFiles%28%29

I don't write VB, but it looks alright to me.

Code:
Dim fiArr As FileInfo() = di.GetFiles.[COLOR=#66cc66]Where[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#b1b100]Function[/COLOR][COLOR=#66cc66]([/COLOR]fi[COLOR=#66cc66])[/COLOR] fi.[COLOR=#66cc66]Extension[/COLOR] = [COLOR=#ff0000]".avi"[/COLOR] OrElse fi.[COLOR=#66cc66]Extension[/COLOR] = [COLOR=#ff0000]".mpg"[/COLOR] OrElse fi.[COLOR=#66cc66]Extension[/COLOR] = [COLOR=#ff0000]".mkv"[/COLOR] OrElse fi.[COLOR=#66cc66]Extension[/COLOR] = [COLOR=#ff0000]".mp4"[/COLOR][COLOR=#66cc66])[/COLOR].[COLOR=#66cc66]ToArray
[/COLOR]