php - how do i modify the way in which readdir() lists files. -


I have a script that creates a daily code in the zip code followed by another script The 'final' file is deleted in the directory, so I always have the latest x days

  while (wrong! == ($ file = readdir ($ handle))) {If ($ file! = "." & Amp; $ file! = "..") { Resonant "$ file"; Echo '& lt; Br> & # 39; & # 39; // 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   

The oldest file is being deleted, rather than obviously.

When I see the files in FTP, all the dates are correct.

Why is readdir () returning them out of order in this matter? How do I want it, how do I apply it to order? (According to date)

readdir file names in an arbitrary order Depending on how the OS returns to the entries from the file system, you need to manually sort the results list:

  foreach (Globe ("*") as $ fn) {$ Files [$ fn] = filemtime ($ fn); } Arsort ($ files); $ Files = array_keys ($ files);    

Comments