Question:
I am connecting to a linux server using ssh. I want to list all the files in a directory. I got that part working however they are not in the order I would like. I want to sort by creating date.
Here is the code I am using
$dirListing = $sftp->ReadDir($handle);
if (is_null($dirListing)) { print $sftp->lastErrorHtml() . "n"; exit; }
// Iterate over the files. $sysTime = new SYSTEMTIME();
$n = $dirListing->get_NumFilesAndDirs(); if ($n == 0) { print 'No entries found in this directory.' . "n"; } else { print '
'; print ' '; for ($i = 0; $i <= $n - 1; $i++) { $fileObj = $dirListing->GetFileObject($i);
$filetype = $fileObj->fileType();
if($filetype != "directory") {
?>
<tr>
<td scope="col"><?php print $fileObj->filename(); ?></td>
<td scope="col"><?php print formatBytes($fileObj->get_Size32()); ?></td>
<td scope="col"><?php $fileObj->get_CreateTime($sysTime);print $sysTime->wHour . ":" . $sysTime->wMinute . ' '. $sysTime->wMonth . '/'.$sysTime->wDay. '/'.$sysTime->wYear ."\n"; ?></td>
<td scope="col"> </td>
</tr>
<?php
}
}
print '</tbody></table> ';
}
How do I sort the directory listing by date?
File Name | File Size | Created |
---|