Re: Directoryies and Arrays
| From: | Pavel Jartsev | Date: | Thu, 07 Dec 2000 16:59:59 +0000 |
| Subject: | Re: Directoryies and Arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29159@lists.php.net to get a copy of this message | ||
"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