Author Topic: replace filename  (Read 1300 times)

0 Members and 1 Guest are viewing this topic.

Nick Riviera

  • Newbie
  • *
  • Posts: 22
replace filename
« on: January 17, 2023, 08:43:20 AM »
Hello,
...can I replace a string from a filename with a custom script...?

something like this:

[ReplaceS:replace this|[myScript]]([f])

RTT

  • Administrator
  • *****
  • Posts: 907
Re: replace filename
« Reply #1 on: January 18, 2023, 02:29:20 AM »
Not possible while using the builtin ReplaceS function (the parameters are fixed, not parsed for dynamic content), but doable with a custom script.

With a custom script, named ReplaceStr, with this code:
Code: [Select]
function ReplaceStr() {
    var params = CurrentField.value.split(',', 3);
    if (params.length == 3) {
        return params[0].replace(params[1], params[2]);
    }
}
you can then use this syntax: [ReplaceStr](source,searchValue,newValue)
With your example: [ReplaceStr]([F],replace this,[myScript])

Nick Riviera

  • Newbie
  • *
  • Posts: 22
Re: replace filename
« Reply #2 on: January 18, 2023, 08:20:00 AM »
thank you for reply and  for the explanations
but,
I do not know if the function ReplaceStr does not work or I did not proceed correctly...

01_replace this_document.pdf
the result should be:
01_210x297mm_document.pdf

RTT

  • Administrator
  • *****
  • Posts: 907
Re: replace filename
« Reply #3 on: January 18, 2023, 04:28:20 PM »
In your screenshot the [ReplaceStr] part of the expression is not showing in blue, so your custom scripts don't have a script named ReplaceStr. Probably you forgot to rename the newly added script or mistyped the name.

Nick Riviera

  • Newbie
  • *
  • Posts: 22
Re: replace filename
« Reply #4 on: January 19, 2023, 10:04:34 AM »
you're right,my mistake.. it's works..solved!Thanks!