on 28/11/02 12:01 AM, Nick Wilson ([EMAIL PROTECTED]) wrote:
> I have several directories filled with files written like this: > > * 02-09-19-filename.etc > * 02-10-02-anotherfile.whatever > > How does php order these files if read from the directory and printed to > the screen? -- I need them in date order, do I need to sort them > somehow? I think PHP reads them in date created order, or something else... anyhoo, what you need to do is read the filenames into an array, then sort the array, either top-to-bottom or bottom-to-top: <? function files_array_sorted($start_dir, $reverse = 0) { chdir($start_dir); $dir = opendir('.'); while (($myfile = readdir($dir)) !==false) { if(is_file($myfile)) { $files[] = $myfile; } } closedir($dir); chdir('../'); if($reverse) { rsort($files); } else { asort($files); } reset($files); return $files; } foreach(files_array_sorted('dummyfiles',1) as $filename) { echo "{$filename}<br />\n"; } ?> There's an optional second parameter for asort() and rsort(), so check it out in the manual... it *may* be needed to get what you want. Justin French -------------------- http://Indent.com.au Web Development & Graphic Design -------------------- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php