1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
<?php
// repertoire a scanner :
$dir= ".";
// comparateur de date
function dateComparator($a, $b) {
if ($a['date_modification'] == $b['date_modification']) return 0;
return ($b['date_modification'] < $a['date_modification']) ? -1 : 1;
}
// scan du repertoire
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
$fichiers=array();
foreach ($iterator as $path) {
// si il s'agit d'un fichier
if ($path->isFile())
// on cree une matrice d'informations sur le fichier
$fichiers[]= array(
"nom" => pathinfo($path->__toString(), PATHINFO_BASENAME),
"date_modification" => filemtime($path)
);
}
// affichage du tableau de fichiers avant tri par date
echo "<h3>avant tri par date : </h3>";
echo "<hr/>";
foreach($fichiers as $key => $item) {
echo "[".$key."] ".date("d/m/Y H:i:s", $item['date_modification'])." | ".$item['nom']."<br/>";
}
echo "<hr/>";
// tri par date
usort($fichiers, 'dateComparator');
// affichage du tableau de fichiers apres tri par date
echo "<h3>après tri par date : </h3>";
echo "<hr/>";
foreach($fichiers as $key => $item) {
echo "[".$key."] ".date("d/m/Y H:i:s", $item['date_modification'])." | ".$item['nom']."<br/>";
}
echo "<hr/>";
?> |
Partager