Get File with the middle name

Hi everyone
i have a file in folder D:/UiPath/ like this
20230403_123456_abc.csv
20230403_789101_abc.csv

what if i want to take the middle name of the file like 123456 or 789101 only?

Hi,

How about the following expression?

yourString.Split({"_"c})(1)

OR

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=_).*?(?=_)").Value

image

If your input is full path, please use GetFileName or GetFileNameWithoutExtension as the following.

System.IO.Path.GetFileNameWithoutExtension(yourString).Split({"_"c})(1)

OR

System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileName(yourString),"(?<=_).*?(?=_)").Value

Regards,

1 Like

Hi @samarasenja

You can use the following RegEx pattern to get the middle data from each file name:

(?<=_)\d+(?=_)

UiPath Syntax:

System.Text.RegularExpressions.Regex.Match(filePath.ToString,” (?<=_)\d+(?=_)”).ToString

Hope this helps,
Best Regards.

I mean, I’ll just use the middle name like 123456 or 789101 because the name is static, I use that name as a reference for the read csv file path? can you help me tell the flow plis?

Hi,

If my understanding is right, the following will work. Can you try this?

Condition

System.Text.RegularExpressions.Regex.Match(CurrentFile.Name,"(?<=_).*?(?=_)").Value=targetNumber

Regards,

1 Like

Hi this is solved, thank you

1 Like

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