RTTSoftware Support Forum

PDF-ShellTools => Ideas/Suggestions => Topic started by: Nick Riviera on January 17, 2023, 08:43:20 AM

Title: replace filename
Post by: Nick Riviera 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])
Title: Re: replace filename
Post by: RTT 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])
Title: Re: replace filename
Post by: Nick Riviera 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
Title: Re: replace filename
Post by: RTT 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.
Title: Re: replace filename
Post by: Nick Riviera on January 19, 2023, 10:04:34 AM
you're right,my mistake.. it's works..solved!Thanks!