Read Files with Both Lower and upercase

Hi All ,

Can anyone please tell me how to assign only in one variable to get all the files for Both Lower and Upper case extension?

For Example : 1) “.PDF” and “.pdf” and 2) “.txt” and “.TXT”

Thank you inadvance

Hi @Ayekpam_Sonu,

You can use this sytax to get files.
Directory.EnumerateFiles(“C:\path”, “.”, SearchOption.AllDirectories) .Where(function(x) x.EndsWith(“.pdf”) or s.EndsWith(“.PDF”))

You can even assign pdf to a variable called type and use that as below
Directory.EnumerateFiles(“C:\path”, “.”, SearchOption.AllDirectories) .Where(function(x) x.EndsWith(type) or s.EndsWith(type.ToUpper))

Hope this solves your issue


Check the solution provided here Wildcard file path
. Replace xlsx with pdf & txt as per need.


Hi ,

Thank you so much. :slightly_smiling_face:

I tried with the first one and it worked
Directory.EnumerateFiles(in_PDF_Path, “.”, SearchOption.AllDirectories) .Where(function(x) x.EndsWith(“.pdf”) or x.EndsWith(“.PDF”))


Hi @Ayekpam_Sonu,

Please mark the post by @shivagowdavarad as solution.

@shivagowdavarad: An alternative way of your query would be to convert to specific case instead of 2 conditions:
Directory.EnumerateFiles("<FilePath>", ".", SearchOption.AllDirectories) .Where(function(x as String) x.ToLower().EndsWith(".pdf"))

Happy Automating!


1 Like

Nice to hear! @Ayekpam_Sonu
Happy automation :sweat_smile:

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