Load filenames of a dir on an array
| From: | Nando2 | Date: | Tue, 12 Dec 2000 00:14:31 +0000 |
| Subject: | Load filenames of a dir on an array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-29775@lists.php.net to get a copy of this message | ||
Pedro,
Try this!
regards,
Carlos Fernando.
<?
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>
----------------