Re: [PHP] sorting results of opendir()
On 09-Jul-01 Steve Edberg wrote: > Here's one way: > > > $dir = opendir('.'); > unset($FileList); > > while ($file=readdir($dir)) { > > if($file!= '.' && $file != '..') > { > $FileList[] = $file; > } > > } > > sort $FileList; > reset($FileList); > > while(list(, $F) = each($FileList)) { > > echo "$F\n"; > > } > > If you're using PHP4, you can replace everything after the > sort($FileList) with the more compact: > > foreach($FileList as $F) { echo "$F\n"; } > > > See > > http://www.php.net/manual/en/function.sort.php > > for more info on sorting arrays. > > > - steve > > > > At 1:05 PM -0500 7/9/01, kmurrah wrote: >>Greetings. >> >>I need to read the contents of a directory, sort it alphabetically, and >>display it >> >>i'm doing find on the reading and displaying, but can someone help me with >>the sort? >> >>$dir = opendir("."); >> >>while ($file=readdir($dir)) { >> >> >> if($file!= "." && $file != "..") >> { >> echo("$file"); >> } >>} >> > > > -- > +-- Factoid: Of the 100 largest economies in the world, 51 are --+ >| Steve Edberg University of California, Davis | >| [EMAIL PROTECTED] Computer Consultant | >| http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | > +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] sorting results of opendir()
Just store each $file into an array ($array[] = $file) and the sort($array). Works dandy => Ben Quoting kmurrah <[EMAIL PROTECTED]>: > Greetings. > > I need to read the contents of a directory, sort > it alphabetically, and > display it > > i'm doing find on the reading and displaying, > but can someone help me with > the sort? > > > $dir = opendir("."); > > while ($file=readdir($dir)) { > > > if($file!= "." && $file != "..") > { > echo("$file"); > } > } > > > > > > thanks, > > kennm > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] sorting results of opendir()
Here's one way: $dir = opendir('.'); unset($FileList); while ($file=readdir($dir)) { if($file!= '.' && $file != '..') { $FileList[] = $file; } } sort $FileList; reset($FileList); while(list(, $F) = each($FileList)) { echo "$F\n"; } If you're using PHP4, you can replace everything after the sort($FileList) with the more compact: foreach($FileList as $F) { echo "$F\n"; } See http://www.php.net/manual/en/function.sort.php for more info on sorting arrays. - steve At 1:05 PM -0500 7/9/01, kmurrah wrote: >Greetings. > >I need to read the contents of a directory, sort it alphabetically, and >display it > >i'm doing find on the reading and displaying, but can someone help me with >the sort? > >$dir = opendir("."); > >while ($file=readdir($dir)) { > > > if($file!= "." && $file != "..") > { > echo("$file"); > } >} > -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] sorting results of opendir()
Why don't you add the $file to an array, then do a sort on the array? sort($array) Jeff > -Original Message- > From: kmurrah [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 09, 2001 2:06 PM > To: [EMAIL PROTECTED] > Subject: [PHP] sorting results of opendir() > > > Greetings. > > I need to read the contents of a directory, sort it alphabetically, and > display it > > i'm doing find on the reading and displaying, but can someone help me with > the sort? > > > $dir = opendir("."); > > while ($file=readdir($dir)) { > > > if($file!= "." && $file != "..") > { > echo("$file"); > } > } > > > > > > thanks, > > kennm > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] sorting results of opendir()
Greetings. I need to read the contents of a directory, sort it alphabetically, and display it i'm doing find on the reading and displaying, but can someone help me with the sort? $dir = opendir("."); while ($file=readdir($dir)) { if($file!= "." && $file != "..") { echo("$file"); } } thanks, kennm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]