nikefido Posted April 25, 2008 Share Posted April 25, 2008 What order does PHP read through a directory? I am getting a list of folders and files back when I recursively run through directories - however, they don't seem to be coming back in any particular order.. Does anyone have any light to shed on this matter? Perhaps a way to order the files? Link to comment https://forums.phpfreaks.com/topic/102932-php-readdir-order/ Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 The manual says that they are returned in the order that they are stored in the filesystem, which could be just about anything http://us.php.net/readdir You could read all of your filenames into an array and then sort the array with one of PHP's many array sorting functions http://us3.php.net/manual/en/function.sort.php Link to comment https://forums.phpfreaks.com/topic/102932-php-readdir-order/#findComment-527285 Share on other sites More sharing options...
ucffool Posted April 25, 2008 Share Posted April 25, 2008 If you just want the list of contents, use scandir(). It will sort it alphabetically in ascending order by default, or with an optional flag set, in descending order. Link to comment https://forums.phpfreaks.com/topic/102932-php-readdir-order/#findComment-527290 Share on other sites More sharing options...
nikefido Posted April 25, 2008 Author Share Posted April 25, 2008 If you just want the list of contents, use scandir(). It will sort it alphabetically in ascending order by default, or with an optional flag set, in descending order. Thanks I'll check this out. Right now it's using the directory helper found in the Code Igniter framework - which luckily is very easy to extend and hack. I'll try messing with it to get a file list in alphabetical order. Thanks for the tips. Please keep them coming if anyone has any other thoughts Link to comment https://forums.phpfreaks.com/topic/102932-php-readdir-order/#findComment-527323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.