Ordering files from a folder?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Ordering files from a folder?

Post by Mr. Tech »

You know when you use this code to select files out of a folder:

Code: Select all

<?php
$handle=opendir(".");
while ($file = readdir($handle)) {
	if (is_file("./$file")) {
		print $file;
}
closedir($handle); 
?>
It orders them alpabetically. Is it possible to change the way it is ordered? ASC, DESC, extensions etc...

Thanks
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

you can take them to an array and use then array functions like sort etc..
Post Reply