Riniminare file immagine *.CR2

Ciao,
Ho dei file immagine di una fotocamera canon nominati di base con "IMG_xxxx.CR" dove xxxx è un numero progressivo.
Normalmente li rinomino inserendo data e ora immagine secondo il seguente formato:
yyyymmdd_IMG_hhmmss_xxxx.CR2
Ora per una serie di files dovrei modificare il formato ora in modo da diminuire/aumentare i valori di hh e mm di un valore fisso (nel caso attuale hh - 1 e mm - 20).
E' possibile farlo? qualcuno mi sa indicare come?

Grazie
Reply to #1:

Welcome Paolo!

One way to do that is with a script method. (See https://www.advancedrenamer.com/user_guide/v4/method_script )

1) Create a new script method and paste this next code in the "function(index, item)" block. Be sure to press the "Apply script" button:

//-------------------------------------------------------
// "function( index, item)" script
//-------------------------------------------------------
//-- Set these six constants to taste:
const deltaSeconds = 0;
const deltaMinutes = -20;
const deltaHours = -1;
const deltaDays = 0;
const deltaMonths = 0;
const deltaYears = 0;

//-- Convert from "yyyymmdd_IMG_hhmmss_xxxx" to "YYYY-MM-DDTHH:mm:ss" format (xxxx is a sequencer here)
let fRegex = /^(.*)(\d{4})(\d{2})(\d{2})_IMG_(\d{2})(\d{2})(\d{2})(.*)$/;
let oldFileName = item.newBasename;
let stdTimeStr = oldFileName.replace (fRegex, "$2-$3-$4T$5:$6:$7");
let fPrefix = oldFileName.replace (fRegex, "$1");
let fSuffix = oldFileName.replace (fRegex, "$8");

let timeObject = new Date (stdTimeStr);
if (isNaN (timeObject.getTime () ) ) {
return "ERROR IN TIME FORMAT";
}
//-- Now offset the date. We do it this way so that over/under-flows roll correctly.
timeObject.setSeconds (timeObject.getSeconds() + deltaSeconds);
timeObject.setMinutes (timeObject.getMinutes() + deltaMinutes);
timeObject.setHours (timeObject.getHours() + deltaHours );
timeObject.setDate (timeObject.getDate() + deltaDays );
timeObject.setMonth (timeObject.getMonth() + deltaMonths );
timeObject.setFullYear (timeObject.getFullYear() + deltaYears );

//-- Rebuild the adjusted filename:
let dateStr = app.formatDate (timeObject, "yyyymmdd");
let timeStr = app.formatDate (timeObject, "hhnnss");

return fPrefix + dateStr + "_IMG_" + timeStr + fSuffix;
//-------------------------------------------------------

That will adjust the filenames by 80 minutes as you requested.

There may be better ways yo do your overall task depending on your true workflow, but the above answers the problem as posed here.

Hope that helps.

Regards,
Randy
Reply to #2:

Paolo, Randy... ciao buckaroos! :)

There's a built-in way to do that, and it gives the possibility of using a fallback date without adding a conditional to the script. One replace method:

Replace: IMG_(\d+)
With: <DateTaken:yyyymmdd:-1h-20n>_IMG_<DateTaken:hhnnss:-1h-20n>_$1
Case sensitive: Checked
Reg Expr: Checked
Apply to: Name

Use whatever date/time tag you need. Note the "n" for minutes in the modifiers.

Paolo, you shouldn't have this problem since all your files come from the same camera, but if a fallback date/time tag is needed it can be added like this:

Replace: IMG_(\d+)
With: <DateTaken||DateTime:yyyymmdd:-1h-20n>_IMG_<DateTaken||DateTime:hhnnss:-1h-20n>_$1


Check out date time modifiers and tag modifiers in the User Guide. I'd provide links but I'm not sure it's the same in the Italian language version. Styb should be able to tell you. :)

By the way, I added the time modifier to the date portion in case the modifier causes the date to roll back one day. I don't have a way to check that but I'm assuming that is needed.

Best,
DF
Reply to #3:
Grazie ragazzi,
Perfetta la soluzione di DF è proprio quello che mi serve.
In realtà il testo inserito nel metodo di sostituzione è:

Nome File Originale: IMG_xxxx (xxxx = numero progressivo)
Sostituisci: IMG_
Sostituisci Con: <Img DateOriginal:yyyymmdd>_IMG_<Img DateOriginal:hhmmss:-1h-20n>_

Inserendo IMG_(\d+) e $1 dopo la stringa di sostituzione, il metodo non funziona.

Grazie di nuovo, saluti
P