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
Change created & modified date for files & folders to filename date
Change created & modified date for files & folders to filename date
Last edited by Schuller on 19 Nov 2024 08:57, edited 1 time in total.
Re: Change created & modified date for files & folders to filename date
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;
}
One of my scripts helped you out? Please donate via Paypal
Re: Change created & modified date for files & folders to filename date
Works perfect!
Thanks
Thanks
Re: Change created & modified date for files & folders to filename date
My pleasure 
One of my scripts helped you out? Please donate via Paypal
Re: Change created & modified date for files & folders to filename date
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
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
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;
}
One of my scripts helped you out? Please donate via Paypal
Re: Change created & modified date for files & folders to filename date
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?highend wrote: ↑18 Nov 2024 12:11Code: 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
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;
}
One of my scripts helped you out? Please donate via Paypal
Re: Change created & modified date for files & folders to filename date
Thank you very much!
XYplorer Beta Club