I have a script that creates a zip
package daily in a directory. After this is done another script deletes the 'last' file in the directory so I always have just the latest x days.
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
echo "$file";
echo '<br>';
//count files
$file_count = $file_count + 1;
}
}
However suddenly readdir()
is returning the list of files like this:
March_16_2011.zip
March_12_2011.zip
March_13_2011.zip
March_14_2011.zip
March_15_2011.zip
So of course rather than the oldest file being removed the newest one is.
When I look at the files in FTP they are all dated correctly.
Why is readdir()
returning them out of order in this case? How do I force it to order them in a way I want? (By date)