How to pass multile file extension in Get Files

Directory.GetFiles(tempFolder,“*.jpg”,SearchOption.AllDirectories)

How to pass multiple file extension in directory.getfiles.

I used this also
Directory.GetFiles(tempFolder, “.”, SearchOption.AllDirectories).Where(Function(s) s.EndsWith(“.jpg”) Or s.EndsWith(“.jpeg”))

But getting error

Varaible used

Hi @Puneet_Singh1

Try this:

extensions = {".txt", ".csv", ".xlsx"}

files = Directory.GetFiles("C:\FolderPath", "*.*", SearchOption.AllDirectories).Where(Function(f) extensions.Contains(Path.GetExtension(f)))

Regards,

Hi,

Take a list or array of extensions and then try to loop these extensions in for loop.

I hope this helps

@Puneet_Singh1

Please try this

Directory.GetFiles("FolderPath","*",SearchOption.AllDirectories).Where(function(x) x.ToLower.EndsWith(".jpg") Or x.ToLower.EndsWith(".jpeg")).ToArray

basically .ToArray needs to be used

cheers

Extension is list type right

No, its an array of string.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.