Scripting error with app.prevItem

Advanced Renamer forum
#1 : 02/02-16 13:35
Tester123
Tester123
Posts: 92
I'm just trying out the scripting method (particularly the app.prevItem object) using the following files:
Test1.txt
Test2.txt
Test3.txt

And using this script:

function(index, item) {
var currFile = item.name;
var prevFile = (index == 0) ? 'undefined' : app.prevItem.name;
return currFile + '_' + prevFile;
}

I was expecting to see this as the result:
Filename New-Filename
------------ -------------------
Test1.txt Test1_undefined.txt
Test2.txt Test2_Test1.txt
Test3.txt Test3_Test2.txt

But instead I see this:
Filename New-Filename
------------ -------------------
<Blank> <Blank>
Test2.txt Test2_.txt
Test3.txt Test3_Test2.txt

For some reason, the filename of the first file vanishes when the script is applied, which results in the 'New Filename' also being blanked out. Only the third file gives the correct result.

Is there an issue with the app.prevItem object, or am I doing something wrong?

Using v3.70 if that helps.


02/02-16 13:35 - edited 02/02-16 14:36
#2 : 17/06-16 07:00
G. Lambany
G. Lambany
Posts: 187
Reply to #1:
Had the same kind of problem with your code, which make a lot of sense.. I dunno

this one works tho (doesnt support method before it, and I dont think it is even possible):

function(index, item) {
return (index == 0) ? item.name + '_Untitled' : item.name + '_' + app.getItem(index - 1).name;

tested in v3.72

cheers!


17/06-16 07:00 - edited 17/06-16 07:27
#3 : 18/06-16 10:01
Tester123
Tester123
Posts: 92
Reply to #2:
Thanks Guillaume, your alternative approach does the trick! I was trying to use it to solve a question posed by another forum user but gave up because of what I perceived to be a bug with the app.prevItem object.


18/06-16 10:01