0

I recently started a internship where I get to code UiPath which is all new to me. I'm wondering (and I hope I can phrase this correctly) if there is a way to remove the extension of a filename (if there is one) using regular expression, whilst passing the argument to it's function.

For ex. I want to print my file "exampleFile.exe" as just "exampleFile" without actually changing the variable itself.

I cant figure out how to incorporate the RegEx I currently have to remove everything after the last "." found in a string. This is the expression I have: /\.[^.]*$/

I will also append a screenshot of the actual code I'm working with.

This code currently creates a file named "(Current file name).xml_metadata.xml" and I of course only want .xml at the very end

destinationFolderPath + "\" + CurrentFile.Name + "_metadata.xml"

My Workspace, it's the Write to filename part which is insteresting here. It's opened in the editor on the side.

Hope any kind soul can help a struggling junior out!

Tried to remove the ending of a string and it just throws me an error.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

0

You can replace CurrentFile.Name with

Regex.Replace(CurrentFile.Name, @"\.[^.]*$", "", RegexOptions.RightToLeft)

Note that you should not use regex delimiters in .NET patterns.

The RegexOptions.RightToLeft option allows for efficient pattern search from the end of the string.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563