OL Learn

Script to replace - in the name of a file

I have this file 123-ABC.xml. Is there a script to replace - ?

  • Store the name of the file inside a variable.
  • Run a script as follow using Enhanced JScript as the language:
    Watch.SetVariable(“var name”,Watch.GetVariable(“var name”).replace("-",“what ever you want”));
  • Use the Rename plugin to rename the file with the content of the variable you used.

Make sure you use proper quote or double quote. Do not copy paste those that show in here :wink: .

thks for your answer

Hi @nabel1510,

Please note that instead of Watch.GetVariable("variableName") you can also consider to use Watch.GetOriginalFileName() whereby the example shared by @hamelj will become something like:

Watch.SetVariable("variableName", Watch.GetOriginalFileName().replace("-", "_");

Source: ‘Watch.GetOriginalFileName - PlanetPress Workflow 2022.1 User Guide (link)’