Assign the date from the file with name "IMG_20250922_204023" to the file modification date (with JavaScript):
- Code: Select all
// Parse dates from filenames like IMG_20250922_204023 and set the file’s modified timestamp accordingly
// Example name before: "IMG_20250922_204023"
// After running this, newModified will be Date corresponding to 2025-09-22 20:40:23
var m = name.match(/^IMG_(\d{8})_(\d{6})/);
if (m) {
// m[1] = "20250922", m[2] = "204023"
var da = m[1], ti = m[2];
var year = parseInt(da.substr(0,4), 10);
var month = parseInt(da.substr(4,2), 10) - 1; // zero-based
var day = parseInt(da.substr(6,2), 10);
var hour = parseInt(ti.substr(0,2), 10);
var minute = parseInt(ti.substr(2,2), 10);
var second = parseInt(ti.substr(4,2), 10);
newModified = new Date(year, month, day, hour, minute, second);
}
// Keep the filename unchanged
newName = name;