#1 : 10/11-22 20:45 Tucoco
Posts: 7
|
I have found out in thousands of files i had from downloads from like 1-2 years ago something. The app i used in the past no longer works and now im using other but it download it with a 3 hour difference compared to my old database.
What i need is a way to batch change the hour difference in filenames and in some cases even the day of all my old database. For example i need to change from this 2021-02-11 11.24.09 -> 2021-02-11 14.24.09 In cases it changes day it need to take that in account automatically: 2020-05-09 21.45.21 -> 2020-05-10 00.45.21 What kind of commands need to add the ARen? |
#2 : 11/11-22 20:34 David Lee
Posts: 1125
|
Use a Script method.
Extract Y, M, D, h, m & s using a regular expression match. Add 3 to h Create a new Date Extract Y, M, D, h, m & s from the new date Format and return. This script should do it: deltaHour = 3; match = item.name.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2})\.(\d{2})\.(\d{2})/); log(match); if (match) { Y = 1*match[1]; M = 1*match[2] - 1; D = 1*match[3]; h = 1*match[4]; m = 1*match[5]; s = 1*match[6]; h += deltaHour; date = new Date(Y, M, D, h, m, s); Y = date.getFullYear(); M = date.getMonth() + 1; D = date.getDate(); h = date.getHours(); m = date.getMinutes(); s = date.getSeconds(); return Y + "-" + ("0" + M).slice(-2)+ "-" + ("0" + D).slice(-2) + " " + ("0" + h).slice(-2) + "." + ("0" + m).slice(-2) + "." + ("0" + s).slice(-2); } |
#3 : 13/11-22 07:30 Tucoco
Posts: 7
|
Reply to #2:
Wow that is amazing, thanks. Just one question how can i make it respect the rest of the filename without deleting it? 2020-05-09 21.45.21 xxxxxxxxxxxxx.jpg -> 2020-05-10 00.45.21 xxxxxxxxxxxxx.jpg |
#4 : 13/11-22 11:19 David Lee
Posts: 1125
|
Reply to #3:
deltaHour = 3; match = item.name.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2})\.(\d{2})\.(\d{2})(.*)/); if (match) { Y = 1*match[1]; M = 1*match[2] - 1; D = 1*match[3]; h = 1*match[4]; m = 1*match[5]; s = 1*match[6]; h += deltaHour; date = new Date(Y, M, D, h, m, s); Y = date.getFullYear(); M = date.getMonth() + 1; D = date.getDate(); h = date.getHours(); m = date.getMinutes(); s = date.getSeconds(); return Y + "-" + ("0" + M).slice(-2)+ "-" + ("0" + D).slice(-2) + " " + ("0" + h).slice(-2) + "." + ("0" + m).slice(-2) + "." + ("0" + s).slice(-2) + match[7]; } |
#5 : 13/11-22 17:37 Tucoco
Posts: 7
|
Reply to #4:
You are very smart, thank you very much. |
#6 : 30/12-22 01:57 Kevin Ludwig
Posts: 2
|
Reply to #5:
If I want to use the following fields off the file metadata, but like the post the time is off by 7 hours to, how can you modify the script to add the hours. In this case, I am removing the entire file name and rebuilding it off the date and time using the Varibles: <Video Date Year><Video Date Month><Video Date Day>_<Video Date Hour><Video Date Min><Video Date Sec> and then i need to change the time by +7 hours, and then I want to just add text at the end like: "DroneVideo" using the "Add" predefined option |
#7 : 30/12-22 13:52 David Lee
Posts: 1125
|
Reply to #6:
The following script will do it... dH = 7; suffix = "_DroneVideo"; date = new Date(item.videoDate); Y = date.getFullYear(); if (Y != 1899) { h = date.getHours(); date.setHours(h+dH); Y = date.getFullYear(); M = date.getMonth() + 1; D = date.getDate(); h = date.getHours(); m = date.getMinutes(); s = date.getSeconds(); return Y + ("0" + M).slice(-2)+ ("0" + D).slice(-2) + "_" + ("0" + h).slice(-2) + ("0" + m).slice(-2) + ("0" + s).slice(-2) + suffix; } The odd statement "if (Y != 1899)" is testing whether the videoDate tag exists before continuing with renaming the file. If the tag is not present then item.videoDate will return a date corresponding to "time zero". For some bizarre reason, apparently originating with Microsoft Works, this corresponds to midnight on 30th December 1899. This only occurs in a script - the error is trapped in other methods and an error message will be displayed. |