How to use multiple extensions while getting file from folder

Hi all,
M downloading file from server and I save it in folder but sometimes file extension is .xlsx or sometimes .XLS so how to write multiple extensions while reading multiple file.
I tried filepath,“.xls”,“.xlsx” but not working

Here is the basic code for how to use Directory.GetFiles to look for multiple extensions.

Directory.GetFiles(SourcePath, “.”, SearchOption.TopDirectoryOnly).Where(Function(s) s.EndsWith(“.xls”) Or s.EndsWith(“.xlsx”) Or s.EndsWith(“.csv”))

1 Like

No that didn’t work for me because I have only perticular file which contains one file either XLS or Xlsx. So if I wrote XLS nd next time file is Xlsx then m getting error

Ohk let’s see will try this .


What is wrong

No, you aren’t. Take the CSV part out and the expression will find a file if its extension is .xls or .xlsx

Directory.GetFiles returns an array.

We do have different options like

arrFilePaths =

Directory.GetFiles("YourPath").Where(Function (x) {".XLS", ".XLSX"}.Contains(Path.GetExtension(x).toUpper)).toArray

But when we want to display the Array items e.g. Message Box, Log we cannot use toString as it is returning the DataType. We can use:

String.Join(" | ", arrFilePaths)

1 Like

what is the type of arrFilePaths still facing error like argument not specified for “Path” of public share function

arrFilePath is a string Array - String()
please check the updated statement, due to some copy-paste issues were corrected

Try this

To:
Ropsfolder+“/”+in_SRno+fileName.split("."c).Last