Re: Directoryies and Arrays
| From: | Brian C. Doyle | Date: | Thu, 07 Dec 2000 17:01:38 +0000 |
| Subject: | Re: Directoryies and Arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29160@lists.php.net to get a copy of this message | ||
Thank you and the other who where nice enough to send almost the same thing. :-)
It works like a charm!!!!
Again Thank you!!!
At 06:59 PM 12/7/00 +0200, Pavel Jartsev wrote:
"Brian C. Doyle" wrote: ... The table list the directories first then the files... That is cool just that the directorys and files. I would like to get them into an order so I thought hey use and array!!! I just can not figure how to write the array in the while loop. ... I hope I didn't misunderstood your question, but the following code will print out directories and files in alphabetic order. ----------------- <? if (!isset($dir)){ $dir=getcwd(); } echo $dir; $dirs = array(); $files = array(); $handle=opendir($dir); while ($file = readdir($handle)) { if (is_dir($file))$dirs[] = $file;else$files[] = $file;} closedir($handle); sort( $dirs ); sort( $files ); ?> <TABLE CELLPADDING="2" CELLSPACING="2"> <? for ( $i = 0; $i < sizeof( $dirs ); $i++ ) { ?> <TR> <TD ALIGN="left" COLSPAN=2><B><? echo $dirs[$i]; ?></B></TD> </TR> <? } for ( $i = 0; $i < sizeof( $files ); $i++ ) { ?> <TR> <TD> </TD> <TD ALIGN="left" WIDTH="100"><?echo $files[$i]; ?></TD> </TR> <? } ?> </TABLE> ---------------- Is this what you need? :) -- Pavel a.k.a. Papi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net