How to change filter criteria in list

Currently i am filtering file with xls extension using below action.
strList =Directory.EnumerateFiles(FolderName, “*.xls”).ToList

how can i modify above condition so that i can filter “xls” and “xlsx” file only


you should be able to do it like
strList =Directory.EnumerateFiles(FolderName, “*.xls*").ToList

Thanks :smiley:

Use + icon to add additional file format.


Please try the following expression:

strList = Directory.EnumerateFiles(FolderName, "*.xls").Where(Function(file) file.ToLower().EndsWith(".xls") Or file.ToLower().EndsWith(".xlsx")).ToList()

Hope this helps,
Best Regards.

1 Like


ou can use the Directory.GetFiles method instead Directory.EnumerateFiles

Can you try with this expression?

Directory.GetFiles("Your FolderPath", "*.xls*").Where(Function(r) r.ToLower().EndsWith(".xls") OrElse r.ToLower().EndsWith(".xlsx")).ToList()


1 Like

Hi @arjunshenoy ,
thanks . actually i wanted all file of extension xls and xlsx. i modified below bold part and it work . thanks

strList = Directory.EnumerateFiles(FolderName, “*.*).Where(Function(file) file.ToLower().EndsWith(“.xls”) Or file.ToLower().EndsWith(“.xlsx”)).ToList()

1 Like


Glad you figured it out. Happy Automation!

Best Regards.

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