Ultimately, I'd like to be able to get an array of all of the files in a directory and reorder them, say, by file creation time (fileCTime).
Example code:
<?php
// Basically a DirectoryIterator with a few utility functions
class File_Linux extends DirectoryIterator {
// Format to use for fileCTime timestamps
const CTIME = '%c'; function __toString()
{
$file = $this->current();
return '<file>' .
'<name>' . $file->getFileName() . '</name>' .
'<type>' . $file->getType() . '</type>' .
'<ctime>' . strftime(self::CTIME, $file->getCTime()) . '</ctime>' .
'<size>' . $file->getSize() . '</size>' .
"</file>\n";
} function sortCTime(DirectoryIterator $file1, DirectoryIterator $file2)
{
$time1 = $file1->getCTime();
$time2 = $file2->getCTime();
if ($time1 == $time2) {
return 0;
}
return $time1 > $time2 ? 1 : -1;
}
}$fm = new File_Linux('./');
echo '<pre>';// Doesn't work - right number, put properties get lost
foreach ($fm as &$file) {
$list[] = clone $file;
}
usort($list, array('File_Linux', 'sortCTime'));
print_r($list);// Doesn't work either
foreach ($fm as &$file) {
$list2[] =& $file;
}
usort($list2, array('File_Linux', 'sortCTime'));
print_r($list2);?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

