note 24581 added to function.opendir
| From: | erian96 at hotmail dot com | Date: | Thu, 22 Aug 2002 00:56:13 +0000 |
| Subject: | note 24581 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35344@lists.php.net to get a copy of this message | ||
how I can make to list all the directories who exist as well within a directory and first contain
other directories. I have made the following attempt and single it lists the directories to me of an
inferior level.
<?php
function listar_directorio($dir) {
if (($dir == ".") || ($dir == "..")) { return; }
if (($manejador = @opendir($dir)) == false) {
echo "opendir() falló en '" . $dir. "', razón: " . $manejador
. "<br>";
return;
}
echo "<hr align='center' width='60%' noshade size='1'
color='#C0C0C0'>";
echo "<div align='center'><b>" . $dir .
"</b><br>";
while ($archivo = readdir($manejador)) {
if ((strpos($archivo, ".") == false) && (strlen($archivo) > 2)) {
listar_directorio($archivo);
} else {
if($archivo == "." or $archivo == "..") continue;
if (strpos($archivo, ".") == false) {
echo "<a href='$dir\\$archivo'>$archivo.</a><br>";
} else {
echo "<a href='$dir\\$archivo'>".
substr($archivo,0,strpos($archivo, ".")-strlen($archivo)).
"</a><br>";
}
}
}
echo "<hr align='center' width='60%' noshade size='1'
color='#C0C0C0'></div>";
closedir($manejador);
return;
}
listar_directorio("musica");
?>
--
http://www.php.net/manual/en/function.opendir.php
http://master.php.net/manage/user-notes.php?action=edit+24581
http://master.php.net/manage/user-notes.php?action=delete+24581
http://master.php.net/manage/user-notes.php?action=reject+24581