Sort directory listing using RecursiveDirectoryIterator
Posted
by Scott Saunders
on Stack Overflow
See other posts from Stack Overflow
or by Scott Saunders
Published on 2010-05-28T15:44:36Z
Indexed on
2010/05/28
20:22 UTC
Read the original article
Hit count: 286
I'm using RecursiveDirectoryIterator and RecursiveIteratorIterator to build a file listing tree using code like below. I need to the list to be sorted - either directories then files alphabetically, or just alphabetically.
Can anyone tell me how to sort the file list?
$dir_iterator = new RecursiveDirectoryIterator($groupDirectory);
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
// do stuff with $file
}
© Stack Overflow or respective owner