I have a sample script below to illustrate a problem.
I have a fixed rename internal command string inserted as you can see for debug reasons.
The expected result is to add the suffix _P01_1 to any selected files. No other action.
I am running the script on 2 files in a test folder as shown.
When I run the script on the 2 files there are no errors but the files are not renamed as expected.
The debug output shows the rename internal command that is being executed within the script via the cmd.RunCommand(cmdLine) method.
When I copy the rename command from the debug output and execute it on the same 2 files via the Find-as-you-type Field then the command has the desired and expected effect of adding the suffix.
I have tried a simpler REGEX as follows with identical result:
rename PATTERN "(.*)" TO "\1_P01_1" REGEXP IGNOREEXT
Why does the script not work but the FAYT internal command does?
function OnClick(clickData)
{
// 005 Playing with cmdLine string
// Script does not work
// However if you manually implement the cmdLine output from the debug into the > field it does work
// Why?
// 006 Simplify
//
DOpus.ClearOutput
var pad = 2;
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
var selected = clickData.func.sourcetab.selected;
var count = selected.count;
var current = count;
for (var eSel = new Enumerator(selected); !eSel.atEnd(); eSel.moveNext())
{
var item = eSel.item();
oldPath = item.name;
DOpus.Output("0100 oldPath ="+ oldPath);
var cmdLine = 'rename PATTERN "(\\d{4}-\\d{2}-\\d{2} \\d{2}h\\d{2}m\\d{2}) (.*)" TO "\\1 \\2_P01_1" REGEXP IGNOREEXT'
// var cmdLine = 'Rename FROM="' + oldPath + '" PATTERN=* TO="' + newName + '"';
DOpus.Output("cmdLine :" + cmdLine);
cmd.ClearFiles();
cmd.RunCommand(cmdLine);
}
}