Quote:
Originally Posted by errigour
I was hoping if someone might show me a method for making a directory list sorted by the date that the directories where created and not by the date they where modified by.
|
Unfortunately most filesystems do not retain that timestamp at all. And, as you've noticed, the mtime timestamp is updated for the directory whenever a file is created, deleted, or renamed in that directory.
You could use the directory status change timestamp, though. It is only updated when the directory access mode, owner, group, or other ("inode") attributes are changed. Operations on files in that directory do not affect that timestamp at all.
For this change, just replace
'filemtime' with
'filectime'.
An alternative option is to create a hidden file, say
.created in each directory, and use its timestamp instead. In that case you would use a helper function, say
'timecreated' instead of
'filemtime':
PHP Code:
function timecreated($directory)
{
$result = @filemtime($directory . '/.created');
if ($result === FALSE)
$result = @filemtime($directory);
return $result;
}
This version uses the modification timestamp of the
.created file if it exists; if not, it uses the modification timestamp of the specified directory itself. This way you don't need to worry about races when creating new directories.
The
@ in the
filemtime() calls just suppresses all errors and warnings related to that specific call, even if you have warnings enabled.
Hope this helps,