1

I have to list directories by using scandir() function but result array should be sorted according to date and time of directory created.

Regards Deepak

Deepak
  • 1,055
  • 4
  • 13
  • 22
  • Have a look at this question: http://stackoverflow.com/questions/1386092/sorting-files-with-directoryiterator – rojoca Oct 14 '09 at 08:52

4 Answers4

1

you could try backticks

$listOfFiles = `ls -ltr`;

and then use explode to get the into an array format

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
0

With scandir() you cannot.

Check this

NinethSense
  • 8,824
  • 2
  • 23
  • 23
0

Problem can be solved by using filemtime($dirPath) function.

code sample:

if (file_exists($dirPath)) {
    echo "last modified: " . date ("F d Y H:i:s.", filemtime($dirPath));
}
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Deepak
  • 1,055
  • 4
  • 13
  • 22
0

Get results you need into an array and sort it... I'm not aware of a scandir option that can do this directly.

MaxVT
  • 12,989
  • 6
  • 36
  • 50