RENAME internal command appears not working from within clickData.func.command object

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);
	}
}

No files in the command object, no files referenced in the command statement - nothing to do for Rename.

Thanks for reply @Ixp not sure what you mean, could you rephrase?
The debugs show both files that were selected.
Does that clarify anything?

Yes. But...

cmd.ClearFiles();

So... insert

cmd.AddFile(item);

before

cmd.RunCommand(cmdLine);

and you should be ok.

2 Likes

Bingo. Sorted... thanks.
Very strange I am playing with the script @Leo wrote in this post:
Rename Dialog sequential Numbering downwards
You had some input @Ixp I think.
In that script there is no cmd.AddFile(item) and it works fine.
Hmmm.....
Working anyway thanks alot...

Yes, it uses the alternative method Rename FROM=...

Ahhh.... :slight_smile:

Thanks again.