Renaming images in specific sequence

Advanced Renamer forum
#1 : 12/02-20 16:52
Shan
Shan
Posts: 2
All, I'm new to the software and in the initial stages of learning curve. I have bunch of images that I want to rename in following way -

Original name Updated name
<something_random>.jpg G1_001_front
<something_random>.jpg G1_001_back
<something_random>.jpg G1_002_front
<something_random>.jpg G1_002_back
<something_random>.jpg G1_003_front
<something_random>.jpg G1_003_back

In general naming pattern will be
G1_xxx_yy; where yy will have 2 values, "front" and "back" and xxx will start from 001 and end at 999. All images are already arranged in chronological order.

I'm not able to find a function that will allow me to do this. Any help is appreciated!

Thanks
Shan


12/02-20 16:52
#2 : 12/02-20 18:24
David Lee
David Lee
Posts: 517
Assuming the filenames are already in the correct order in the list, this script will do it:

num = Math.ceil((index + 1) / 2 );
side = (index % 2) ? '_back' : '_front';
return 'G1_' + ("00"+num).slice(-3) + side;


"index" is the position of the filename in the list - starting from zero at the top.

The function Math.ceil(x) rounds x UP to the nearest integer.

"%" is the modulo operator and returns the remainder after division, so "index % 2" will be zero if index is odd and 1 if it is even.

"?" is the conditional operator - syntax: (condition) ? value_if_true : value_if_false


For help on JavaScript Google is your friend - you will probably find hits at www.w3schools.com are usually most helpful.


12/02-20 18:24 - edited 12/02-20 18:25
#3 : 13/02-20 21:24
Shan
Shan
Posts: 2
Reply to #2:
Thank you for the elaborate response and providing working solution! I will go through the reference you have pointed out.

Best,
Shantanu


13/02-20 21:24