while ( false !== ( $file = readdir($handle) ) ) { if ($file == '.' || $file == '..') { continue; } if (substr($file,0,$cam_len) != $cam_code) { continue; } $date = strtotime(substr($file,$cam_len,strlen($file)-(4+$cam_len))); $files[$date] = $file; } // end while read dir /* Sort it based on the keys */ rsort($files);