Removing possible file extension using RegEx during Argument passing?

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”

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.

we can do:


multiple ways

  1. Path.GetFileNameWithoutExtension("FullPath")
  2. Path.Split("."c)(0)

Also for your context you can use this CurrentFile.Name.Split("."c)(0) or Path.GetFileNameWithoutExtension(CurrentFile.FullName)


1 Like

Hi @aamirmurtaza67

With out regex you can use the below expression
FilePath is a variable which contains the file path.


Hope it helps!!

Hi @aamirmurtaza67

Try this


You shouldn’t use + to put things together into a full path and filename. This can result in incorrect or missing \ characters in the path. Use Path.Combine

Path.Combine(destinationFolderPath,Path.GetFilenameWithoutExtension(CurrentFile.Name) + "_metadata.xml")