add number from previous file name

Advanced Renamer forum
#1 : 28/05-19 10:51
onur fesel
onur fesel
Posts: 4
hi, I want to add a part of file name from previous file.for example
first file name is box-1_0.00-3.50...and second file name is box-2_-6.00....for a result I want to update second file name as box-2_3.50-6.00...is there a way for it?
Thanks


28/05-19 10:51
#2 : 29/05-19 09:12
David Lee
David Lee
Posts: 1125
Try this script:

if (index == 0) {
return item.newBasename;
} else {
strt = app.getItem(index-1).name.match(/(.*_.*-)(\d\.\d\d)/)[2];
current=item.name.match(/(.*_)(.*)/);
return current[1] + strt + current[2];
}

Note that the order of filenames in the list is important.


29/05-19 09:12 - edited 29/05-19 09:16
#3 : 29/05-19 10:21
onur fesel
onur fesel
Posts: 4
Reply to #2:
it didn't work, may be I am doing something wrong.Is there a way to share screenshot with you?


29/05-19 10:21
#4 : 29/05-19 17:31
David Lee
David Lee
Posts: 1125
Reply to #3:
That's odd - it has worked for me on 3 computers running XP and Windows 7.

Are you sure that copied all the code correctly into a Script method window and selected "Apply to: Name"?

This simplified code should also work:

if (index == 0) {return item.newBasename;}
strt = app.getItem(index-1).name.match(/(.*_.*-)(\d\.\d\d)/)[2];
current=item.name.match(/(.*_)(.*)/);
return current[1] + strt + current[2];

My test data is:

box-1_0.00-3.50.qwerty.txt
box-2_-6.00.uiop.txt
box-3_-7.35.asdf.txt

and the result is:

box-1_0.00-3.50.qwerty.txt
box-2_3.50-6.00.uiop.txt
box-3_6.00-7.35.asdf.txt


29/05-19 17:31
#5 : 30/05-19 08:25
onur fesel
onur fesel
Posts: 4
Reply to #4:
I tried this one with your test data and it worked, my files are jpg can it be the problem?

My data is
Box-1_150.00-154.00.JPG
Box-2_-161.40.JPG
Box-3_-166.80.JPG
Box-4_-171.30.JPG
Box-5_-176.00.JPG
Box-6_-180.20.JPG
Box-7_-184.20.JPG
Box-8_-188.00.JPG
Box-9_-192.50.JPG
Box-10_-196.30.JPG
Box-11_-201.90.JPG
Box-12_-206.30.JPG


30/05-19 08:25
#6 : 30/05-19 09:36
David Lee
David Lee
Posts: 1125
Reply to #5:
The issue is that you incorrectly defined your problem.

You originally specified starting addresses in the format: 3.50 etc - ie a single digit before the decimal point - but you actually have: 154.00 etc

You need only to modify the regular expression that extracts this number from (\d\.\d\d) to (\d*\.\d\d)

so try:

if (index == 0) {return item.newBasename;}
strt = app.getItem(index-1).name.match(/(.*_.*-)(\d*\.\d\d)/)[2];
current=item.name.match(/(.*_)(.*)/);
return current[1] + strt + current[2];


30/05-19 09:36
#7 : 30/05-19 09:53
onur fesel
onur fesel
Posts: 4
Reply to #6:
sorry :(

and thank you that worked perfect :D


30/05-19 09:53
#8 : 30/05-19 10:14
David Lee
David Lee
Posts: 1125
Reply to #7:
Perhaps it may be worth mentioning that app.getItem() (along with other properties and methods of the app object) is an undocumented feature of Advanced Renamer. You will see available properties and methods in a drop-down box when you type "app." into the script window and then try them out for yourself.

Also the usage of Regular Expressions in JavaScript code is a little different from the way they are used in Renamer's methods. You will need to Google online resources for "javascript regex" and experiment to sort out the details.


30/05-19 10:14 - edited 30/05-19 10:15