Page 1 of 1
Replace folder creation date with file date?
Posted: 23 Feb 2016 05:04
by Megalith
Some folders I moved to another drive had their original creation dates replaced. The best way to retrieve those dates would be to refer to the dates of the file(s) within those folders, which aren't touched in copy/move operations. I know I could do this by hand, but since I have to deal with a ton of sub-folders, Is there a script (or program) that could automatically scan and copy the earliest/latest creation date of files in a folder, and then apply that to the root folder?
Re: Replace folder creation date with file date?
Posted: 23 Feb 2016 10:49
by highend
Select the root folder(s) first...
Code: Select all
$log = "";
setting "BackgroundFileOps", 0;
foreach($folder, "<get SelectedItemsPathNames |>") {
$files = folderreport("files:{Created yyyymmddhhnnss}|{fullname}", "r", $folder, "r", , "<crlf>");
if !($files) { continue; }
$files = formatlist($files, "r", "<crlf>");
$item = gettoken($files, 1, "<crlf>");
$file = gettoken($item, 2, "|");
timestamp "c", $file, $folder;
$log = $log . quote($folder) . " got the creation date from: " . quote($file);
}
text $log;
Re: Replace folder creation date with file date?
Posted: 23 Feb 2016 11:59
by PeterH
Another possibility: instead of Move use Backup (preserving dates!) and then Delete.
This also might be advantageous in means of security.
Re: Replace folder creation date with file date?
Posted: 23 Feb 2016 22:35
by Megalith
I really like the script, highend. But is there a way to get the script to copy the earliest date instead of the latest date that is found?
Re: Replace folder creation date with file date?
Posted: 23 Feb 2016 22:39
by highend
What is "the earliest date"?
Re: Replace folder creation date with file date?
Posted: 23 Feb 2016 22:46
by Megalith
Example: Folder has two image files. First image file has creation time of 11:20:30, second image file has creation time of 11:20:35. I want the script to copy the creation time of the first image file, which has the earlier creation date/time.
Re: Replace folder creation date with file date?
Posted: 23 Feb 2016 22:50
by highend
Code: Select all
$files = formatlist($files, "s", "<crlf>");
Re: Replace folder creation date with file date?
Posted: 23 Feb 2016 22:54
by Megalith
Works great!

Re: Replace folder creation date with file date?
Posted: 08 Mar 2016 08:39
by jjiron
My scenario below is such that only the FOLDERS (root and subfolders) received the date of the backup (ie today) while files within them have the correct dates.
Will this script fix those dates as well? IE Root will have the oldest date within the subfolders (2/1999) , and the subfolders the date of the oldest file within it? Subfolder1=2/2004, Subfolder2=2/1999
Root (3/2016)
~Subfolder1 (3/2016)
~~~file1 - dateA (1/2010)
~~~file2- dateB (2/2004)
~Subfolfder2 (3/2016)
~~~file3 - dateA (1/2008)
~~~file4- dateB (2/1999)
Thanks for the clarification - I am in the process of backing 5TB of data and now in the middle of the process realized there is a date issue on many folders and sub-folders,
Re: Replace folder creation date with file date?
Posted: 08 Mar 2016 13:28
by highend
No. The script only sets the creation date for the root folder, not for all subfolders of root.
Try this instead:
Code: Select all
setting "BackgroundFileOps", 0;
foreach($rootFolder, "<get SelectedItemsPathNames |>") {
$oldestFile = "";
foreach($subFolder, quicksearch("/d", $rootFolder, "|")) {
$files = folderreport("files:{Created yyyymmddhhnnss}|{fullname}", "r", $subFolder, "r", , "<crlf>");
if !($files) { continue; }
$files = formatlist($files, "s", "<crlf>");
$item = gettoken($files, 1, "<crlf>");
$file = gettoken($item, 2, "|");
timestamp "c", $file, $subFolder;
$oldestFile = $oldestFile . $item . "<crlf>";
}
$oldestFile = gettoken(gettoken(formatlist($oldestFile, "es", "<crlf>"), 1, "<crlf>"), 2, "|");
timestamp "c", $oldestFile, $rootFolder;
}
Re: Replace folder creation date with file date?
Posted: 08 Mar 2016 17:45
by admin
@jjiron
Curious: What is the idea behind setting the folder date to the date of the oldest file within?
Re: Replace folder creation date with file date?
Posted: 08 Mar 2016 22:10
by TheQwerty
admin wrote:@jjiron
Curious: What is the idea behind setting the folder date to the date of the oldest file within?
Obviously I can't answer for jjiron but it makes some sense to me.
If you have a folder with a created date of March 8, 2016 then it might feel odd for its contents to have a created date earlier than that.
"This files was created before the folder existed?"
Generally, I think many people have a hard time understanding that the folder's dates don't necessarily have any correlation to their content.
EDIT: I'd venture that most people would prefer the folder's created date be that of its oldest descendant and its modified and accessed date correspond to the most recent from its descendants. Clearly, there's performance (and other) problems with this behavior, but it might better match expectations. /edit
Then you see how easy it is to modify any item's date/time and lose trust in them entirely.