Restart increment counter on change of date

Advanced Renamer forum
#1 : 10/04-21 14:40
John Johnson
John Johnson
Posts: 8
I have a single photo directory with photos taken on different dates that extend over a number of months. I rename all the files in the directory with Year, Month, Day, Location where image was taken and a <Inc Nr>. What I would like to do is to restart the Nr when the date changes, resulting in files "grouped by" date, location and unique Nr for the particular date. Is this possible? or is there a different method to achieve this. Many thanks


10/04-21 14:40
#2 : 10/04-21 16:09
David Lee
David Lee
Posts: 1125
Use a Script method.

I'll assume that previous methods have resulted in filenames starting with the format: "YYYYMMDD" and you want to add incrementing numbers starting from 1, zero-padded to 3 digits and with "_" as a separator.

Pre-batch script:
lastDate = "";

Main script:
name = item.newBasename;
if ((date = name.slice(0,8)) != lastDate) {
lastDate = date;
incNo = 0;
}
return name + "_" + ("00" + ++incNo).slice(-3);

This script method must be added after other methods and the files need to be sorted in date order.



10/04-21 16:09
#3 : 12/04-21 03:51
John Johnson
John Johnson
Posts: 8
Reply to #2:
Hi David, being new to the app, (excuse my ignorance), but is there a doc/reference I could use which shows (in simple terms) how the script needs to be set-up in the app?. Many thanks.

Hi David, I found out how to set up the script you sent me. Worked well, except, that the incremental number (shown just before the .NEF) only resets on the year (not the "entire" date); results as follows

2020_11_02_001 1.NEF
2020_11_02_002 2.NEF
2020_11_06_003 3.NEF
2020_11_06_004 4.NEF
2020_11_06_005 5.NEF
2021_01_26_006 1.NEF
2021_01_26_007 2.NEF
2021_01_26_008 3.NEF
2021_01_26_009 4.NEF

Could it be the format of the date that causes this. I used the Nikon <ExifTool:CreateDate> tag to access the date the picture was taken, stripping out the time and adding an incremental Nr. Tag (which works well). Suggestions most welcome. Many thanks

Hi David, I found the issue. I had to change the following from (8) to (12)
if ((date = name.slice(0,12))

Many thanks for the help


12/04-21 03:51 - edited 13/04-21 00:31