[nycphp-talk] Listing files... alphabetically
Robert Dumas
rdumas at cmj.com
Tue Nov 25 17:26:29 EST 2003
I really appreciate the help. Hooo, boy, am I close now.
Here's the current code. It seems to work, with only two problems:
1) it outputs all the filenames under the FIRST bullet point.
2) likely related to #1. the links do not point to the proper subfolders.
function dirlist($path) {
$handle = opendir($path);
$filetlist = array();
$subflist = array();
while ( false !== ($file = readdir($handle)) ) {
if ( ($file!='.') && ($file!='..') && ($file!='index.php') )
{
$filetlist[] = $file;
$subpath = $path.$file;
$subhandle = opendir($subpath);
while ( false !== ($subfile = readdir($subhandle)) )
{
if ( ($subfile!='.') && ($subfile!='..') ) {
$subflist[] = $subfile;
}
}
}
}
natsort($filetlist);
natsort($subflist);
echo '<ul>';
while (list ($key, $val) = each($filetlist)) {
echo '<li>'.$val.'</li>';
echo '<ul>';
while (list ($key, $val) = each($subflist)) {
echo "<li><a href=\"".$val."\">".$val."</li>";
}
echo '</ul>';
}
closedir($handle);
closedir($subhandle);
echo '</ul>';
} // end dirlist()
--RD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20031125/4c13ed75/attachment.html>
More information about the talk
mailing list