How to change filter criteria in list

HI
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

Hi @TUSHAR_DIWASE

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

Thanks :smiley:

Hi @TUSHAR_DIWASE
Use + icon to add additional file format.

Hi @TUSHAR_DIWASE

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

Hi @TUSHAR_DIWASE

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()

Regards
Gokul

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

@TUSHAR_DIWASE

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.