#1 : 17/12-24 18:51 Leo Ooms
Posts: 4
|
In version 3.95.3 The instruction "item.createdDate" worked fine for retrieving the creation date (and time) of the files to be renamed.
I used this a lot to put the creation date in front of the filename for sorting purposes. Since version 4.05 the instruction returns an empty string. What has changed so that this is now unuseable? I also get errors on the <Date Created:format> tag for being an unexpected "<". Could you get this fixed please? Many thanks if you could/would. |
#2 : 18/12-24 08:48 Delta Foxtrot
Posts: 401
|
Reply to #1:
Hi Leo, Yeah, there's something weird about the dates right now. You might try app.parseTags("<DateTimeOriginal>") or something like item.DateTimeOriginal.replace(/:/g, "-") which seems to often give the date/time the file was created (but maybe not always?). EDIT: the statement: return app.parseTags("<DateTimeOriginal:yyyy-mm-dd>_") + item.name ; works fine for me.END EDIT Best, DF |
#3 : 18/12-24 09:03 Kim Jensen
Administrator
Posts: 948 |
Reply to #1:
Date based types are no longer supported in the scripting engine. They might be added back, but as strings in a iso-based format. For now, you will have to use the parseTags approach. The scripting engine for version 4 is very different from the one used in version 3. Differences will occur. |
#4 : 06/01-25 22:21 Colin
Posts: 1
|
Reply to #3:
Hi Kim, Thank you for creating Advanced Renamer—it's an amazing tool, and I really appreciate your hard work on it! I used to rename my images and videos with a script, and it worked well. But now, in ARen 4.07, the script doesn’t work anymore, and I have no idea why. Even ChatGPT couldn’t help me! ;-) I saw that you mentioned Date-based types are no longer supported in the scripting engine. However, I don’t understand how to use the parseTags approach that you suggested. Does this mean I need to keep using ARen 3.xx for my script? Here’s my script: // Funktion zum Hinzufügen von Stunden zum DateTimeOriginal oder CreationDate function addHoursToDateTime(dateTime, hoursToAdd) { // Zerlege das Datum/Zeit-Format in Datum und Zeit var parts = dateTime.split(' '); var dateParts = parts[0].split(':'); var timeParts = parts[1].split(':'); // Extrahiere Jahr, Monat, Tag, Stunde, Minute und Sekunde var year = parseInt(dateParts[0], 10); var month = parseInt(dateParts[1], 10) - 1; // JS-Monate sind 0-basiert var day = parseInt(dateParts[2], 10); var hours = parseInt(timeParts[0], 10); var minutes = parseInt(timeParts[1], 10); var seconds = parseInt(timeParts[2], 10); // Erstelle ein Date-Objekt und füge Stunden hinzu var date = new Date(year, month, day, hours, minutes, seconds); date.setHours(date.getHours() + hoursToAdd); // Formatiere das Ergebnis zurück in das gewünschte Format var formattedDate = date.getFullYear() + '-' + padWithZeros(date.getMonth() + 1, 2) + '-' + padWithZeros(date.getDate(), 2) + '_' + padWithZeros(date.getHours(), 2) + '-' + padWithZeros(date.getMinutes(), 2) + '-' + padWithZeros(date.getSeconds(), 2); return formattedDate; } // Funktion zum Hinzufügen führender Nullen: 3 --> 03 function padWithZeros(value, desiredLength) { var stringValue = String(value); while (stringValue.length < desiredLength) { stringValue = '0' + stringValue; } return stringValue; } // Variable setzt alle Endungen in Kleinbuchstaben var fileExtension = item.extension.toLowerCase(); // Prüfen, ob die Datei ein Bild oder ein Video ist if ( fileExtension === '.jpg' || fileExtension === '.jpeg' || fileExtension === '.png' ) { // Für Bilder: DateTimeOriginal verwenden var dateTimeOriginal = item.exifToolValue('DateTimeOriginal'); if (dateTimeOriginal) { // Variable formattedDate erstellen und Funktion addHoursToDateTime darauf anwenden und 4 Stunden hinzufügen var formattedDate = addHoursToDateTime(dateTimeOriginal, 4); return formattedDate; } else { return item.newBasename; } // Prüfen, ob das Element ein Foto oder ein Video ist. } else if ( fileExtension === '.mp4' || fileExtension === '.mov' || fileExtension === '.avi' || fileExtension === '.mkv' || fileExtension === '.flv' ) { // Für Videos: CreationDate oder CreateDate verwenden var creationDate = item.exifToolValue('CreationDate'); var createDate = item.exifToolValue('CreateDate'); if (creationDate) { // 5 Stunden addieren, weil in Metadaten die UTC und daher 1 Stunde hinterher var formattedDate = addHoursToDateTime(creationDate, 5); return formattedDate; } else if (createDate) { // 5 Stunden addieren, weil in Metadaten die UTC und daher 1 Stunde hinterher var formattedDate = addHoursToDateTime(createDate, 5); return formattedDate; } else { return item.newBasename; } } else { // Für alle anderen Dateitypen: Originaler Dateiname bleibt erhalten return item.newBasename; } Best regards from Germany! :) |
#5 : 07/01-25 20:46 Delta Foxtrot
Posts: 401
|
Reply to #4:
Hi Colin, welcome, "app.parseTags()" is really easy to use, and will make your scripting life easier in ARen. Just put a string in the parentheses, including any tags; most anything you can use in a "New Name" method will work so you can use both string elements and tags, like this: return item.newBasename + app.parseTags( "_<foldername:1>_DATE:_<ExifTool:FileCreateDate:yyyy-mm-dd hh-m-ss>_<IncNrDir:1>" ) ; You can also easily populate an array with date parts like this: myArray = app.parseTags( "<ExifTool:FileCreateDate:yyyy-mm-dd-hh-m-ss>" ).split("-") ; (or, faster): myArray = app.parseTags( "<Date Created:yyyy-mm-dd-hh-m-ss>" ).split("-") ; EDIT: This should do a good part of what you need; once you parseInt() the string date parts you'll have to re-pad the parts, of course: var parts = app.parseTags("<Date Created:yyyy-mm-dd-hh-mm-ss>").split(' '); var year = parseInt(parts[0], 10); var month = parseInt(parts[1], 10) - 1; var day = parseInt(parts[2], 10); var hours = parseInt(parts[3], 10); var minutes = parseInt(parts[4], 10); var seconds = parseInt(parts[5], 10); END EDIT Best, DF |