How to ignore letters case in file names?

Hello all,

it has been so long since I asked a question :smiling_face:

I have an automation that was working for months now and all what it does is to download attachment from email and then read attributes from each file and add it to excel.

today, i found that it stopped working and when I tried to find why, I found that the reason was that one of the files’ name came with capital letters in the (TITLES instead of Title).

the question is: is there any way to ignore the capital case in titles?

yes, you can use regex to get whatever of case

using
image

Hi @firas

Regular Expressions with Case Insensitivity: You can also use regular expressions (Regex) with the case-insensitive flag to perform case-insensitive matching. UiPath provides the IsMatch activity that can be used with regular expressions. Find the below expression for reference.

title1 = "TITLES"
title2 = "Title"

isTitleEqual = System.Text.RegularExpressions.Regex.IsMatch(title1, title2, System.Text.RegularExpressions.RegexOptions.IgnoreCase)

Hope it helps!!

When comparing strings, you can use the String.Equals method with the StringComparison.OrdinalIgnoreCase option. This comparison method ignores the case of the strings being compared. Check the below expression

title1 = "TITLES"
title2 = "Title"

isTitleEqual = String.Equals(title1, title2, StringComparison.OrdinalIgnoreCase)

Happy Autoamation!! @firas

Hi @firas

Try this to get the First letter only capital and remaining or small letters.
fileName.Substring(0,1).ToUpper+fileName.Substring(1).ToLower

thank you for your super fast reply; well i missed stating that I am not a developer and, hence, not good in REGEX

thank you; i am not comparing anything; i just have a do loop that will open each file and read some information and those files are different each day

this is another good thing to try…thank you

Thank you @firas

If you find the solution for your query make Mark it as solution which help others.

Happy Automation!!

Hello @firas

If you are trying to ignore the letter case in selector, then you use case sensitive option.

Check out the link below to ignore case In selector.

@firas

Another way:
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(“fileName”)

I think that I could not explain the issue well!

  • I have a folder that I use to gather the files that I receive via email

  • each file has some information to be copied

  • for example, the file starting with “Data” is a pdf file and some times it comes as “DATA 7-9-2023.PDF” or “data 5-5-2023.pdf” instead of “Data.pdf”; i need my automation to work with all names (each file comes with the date as part of the name so the name is not constant)

  • another file can is prices 7-19-2023.xlsx or PRICES 7-18-2023.xls

You can give a try with wild cards (*) it will help for your issue.

Use the .toLower or .toUpper then it will change to lower for the same and comparision is easy then no case sensitive here.

If it is prices 7-19-2023.xlsx
Then give like this (prices *.xlsx).toLower

Hope it helps!!

this works :slight_smile:

Thank you so much

I used this: CurrentFile.FullName <> string.Format(“(prices *.xlsx).toLower”)

1 Like

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