Using Date of another file in batch

Hello,

I did a takeout of all my pictures i have in Google Photos.
All the pictures and metadata-json-files are set to the current date.
With Aren I could change the date of all the media files. But there are some json-files which have neither the date in their names nor in any metadata.
But there are file pairs like
IMG_9458.JPG
IMG_9458.JPG.supplemental-metadata.json

the JPG-file does have the correct date but the json doesn't.

Is there a chance to do something like
"edit the date of the IMG_9458(....).json file to the date of the IMG_9458.JPG file!"

That would be amazing!

Thanks in advance

Bene
Reply to #1:

Welcome Bene,

Your issue is very similar to: https://www.advancedrenamer.com/forum_thread/pair-renaming-s rt-extensions-double-extensions-17048

If you are comfortable coding, you can adapt that post's answer. If not, I'll post an exact solution here in a few hours (if no one beats me to it).

Regards,
Randy
Okay, here's how you can set the json date to match the jpg date...

1) Create a new script method **AFTER all other renaming methods that you wish to use**.

2) Set "Apply to:" to "Name and extension".

3) Paste this next code in the "Pre batch script" and apply it:
//-------------------------------------------------------
// Pre batch script
//-------------------------------------------------------
nameMap = {};
mstrFileTypes = ["video", "image"]; // Key off of item.mediaType, rather than a finicky list of extensions.

//-- Capture the new names of "Master"/"key" files. Here assumed to be main media files
for (let J = 0, L = app.itemCount; J < L; J++) {
let item = app.getItem (J);
if (mstrFileTypes.includes (item.mediaType) ) {
nameMap[item.name] = {
nwName: item.newBasename,
nwCrtd: item.createdDate, // item.newCreatedDate is broken in Aren 4.20!
nwMod: item.modifiedDate // item.newModifiedDate is broken in Aren 4.20!
// Last Access date is not available
}
}
}
//-------------------------------------------------------

4) Then paste the following code in the "function(index, item)" block and apply it.
//-------------------------------------------------------
// "function( index, item)" script
// This one must apply to "Name and extension".
//-------------------------------------------------------
let baseName = item.name.replace (/^(.+?)\..*$/, "$1"); // Assume that the true filename has no periods.
let fileExtension = item.ext;
if (/\./.test (item.name) ) {
//-- Assume any periods in the "file name" must actually be part of the "extension".
fileExtension = item.name.replace (/^.+?(\..*)$/, "$1") + item.ext;
}
let masterFileData = nameMap[baseName];
if (masterFileData) {
let masterName = masterFileData.nwName;
item.newCreatedDate = masterFileData.nwCrtd;
item.newModifiedDate = masterFileData.nwMod;

return masterName + fileExtension;
}
//-------------------------------------------------------

That'll "getter done". ;)

WARNING: If your current batch has altered the date or time(s) of any files, they will be reset!
This is due to this bug: https://www.advancedrenamer.com/forum_thread/bug-newcreatedd ate-and-newmodifieddate-are-not-readable-17098

So for now, do any date changes in a separate batch before running this script to touch up the json files.

Regards,
Randy
Reply to #3:

Randy! Thank's a lot! It worked really well! :-D

It was a great help!