Page 1 of 1
Change created & modified date for files & folders to filename date
Posted: 18 Nov 2024 10:58
by Schuller
Hi,
I have seen, tried and attempted to modify very similar scripts found in the forum but have not had any success so if someone could please help with a script for my particular situation.
I need a script that will change both the created date and modified date of files and folders that I select to match the filename date. All the filenames start with the date and have characters after that and the dates are all formatted like this: 2024-11-18.
Filename Example: 2024-11-18(CIBC-Qtrade) $100.00
Thanks
Re: Change created & modified date for files & folders to filename date
Posted: 18 Nov 2024 12:11
by highend
Code: Select all
setting "BackgroundFileOps", 0;
$items = <get SelectedItemsPathNames>;
end (!$items), "No item(s) selected, aborted!";
foreach($item, $items, <crlf>, "e") {
$date = regexmatches(gpc($item, "file"), "^\d{4}-\d{2}-\d{2}");
if (!$date) { continue; }
// If you want a different hour:min:second than 00:00:00,
// change it here!
$date .= " 00:00:00";
timestamp "cm", $date, $item;
}
Re: Change created & modified date for files & folders to filename date
Posted: 19 Nov 2024 08:52
by Schuller
Works perfect!
Thanks
Re: Change created & modified date for files & folders to filename date
Posted: 19 Nov 2024 09:56
by highend
My pleasure

Re: Change created & modified date for files & folders to filename date
Posted: 28 Feb 2025 18:18
by Schuller
Hi,
I've tried to modifying some existing scripts to get what I'm looking for but I am having no success for this particular situation.
I"m trying to change both the created date and modified date of files and folders that I select to match the filename date which in this case is only the 4 digit year(yyyy). So all the filenames in question start with the year only and then have varying characters after that. I'm just looking to change the created date and modified to Jan 1st, 12:00am, for both the created and modified.
Filename Examples:
2024_Amazon (change created and modified date to 2024-01-01 12:00am)
2025_Netflix (change created and modified date to 2025-01-01 12:00am)
Thanks
Re: Change created & modified date for files & folders to filename date
Posted: 28 Feb 2025 18:36
by highend
Code: Select all
$items = <get SelectedItemsPathNames>;
end (!$items), "No item(s) selected, aborted!";
setting "BackgroundFileOps", 0;
foreach($item, $items, <crlf>, "e") {
$year = regexmatches(gpc($item, "base"), "^\d{4}");
if (!$year) { continue; }
timestamp "cm", $year . "-01-01 12:00:00", $item;
}
Re: Change created & modified date for files & folders to filename date
Posted: 28 Feb 2025 18:41
by Schuller
Thanks
Re: Change created & modified date for files & folders to filename date
Posted: 24 Jul 2025 21:18
by tomuser
highend wrote: ↑18 Nov 2024 12:11
Code: Select all
setting "BackgroundFileOps", 0;
$items = <get SelectedItemsPathNames>;
end (!$items), "No item(s) selected, aborted!";
foreach($item, $items, <crlf>, "e") {
$date = regexmatches(gpc($item, "file"), "^\d{4}-\d{2}-\d{2}");
if (!$date) { continue; }
// If you want a different hour:min:second than 00:00:00,
// change it here!
$date .= " 00:00:00";
timestamp "cm", $date, $item;
}
How should that script be changed to if file naming format has time included in addition to date, like "20250724_133144.pdf" for example (it may have or may not have additional text in the end before extension but first part is always same - date_time), and then have that time part also used with timestamp "cm" (or just "c" or just "m" based on need) to set correct timestamp for files?
Re: Change created & modified date for files & folders to filename date
Posted: 24 Jul 2025 22:09
by highend
Code: Select all
setting "BackgroundFileOps", 0;
$items = <get SelectedItemsPathNames>;
end (!$items), "No item(s) selected, aborted!";
foreach($item, $items, <crlf>, "e") {
$date = regexmatches(gpc($item, "file"), "^\d{8}_\d{6}");
if (!$date) { continue; }
$pattern = "^(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})";
$date = regexreplace($date, $pattern, "$1-$2-$3 $4:$5:$6");
timestamp "cm", $date, $item;
}
Re: Change created & modified date for files & folders to filename date
Posted: 08 Aug 2025 11:33
by tomuser
Thank you very much!