note 35316 deleted from ref.dir by sniper
| From: | sniper@php.net | Date: | Thu, 15 Dec 2005 23:59:59 +0000 |
| Subject: | note 35316 deleted from ref.dir by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100253@lists.php.net to get a copy of this message | ||
Note Submitter: de \ kibo \ niels
----
Why, here's the millionth recursive directory listing script. The extra added bonus in this
thing is, it lists the directories in a win-explorer-like fashion, with indentation according to
hierarchical depth and such gizmos.
Using the variable $sf, you can control whether files should be displayed. If $sf == 0, only
directories will be shown. This is useful if you just want to see the hierarchical structure of
what's in that path.
The output must be encapsulated in "preformatted" tags, otherwise things will look wild.
Directories are shown in "bold", the explorer-like watchamacallits that show you where you
are, are "italic", so you'd best use CSS to overwrite the standard formatting so it
looks good. I used this:
b {color:blue}
i {font-style:normal; color:gray}
This code can of course be greatly improved upon *hint* :)
<php?
function displaydir ($path, $depth) {
if (($d = @opendir ($path)) === false) echo ('[Could not open path:]');
else {
while ($f = readdir ($d)) {
if ($f != "." && $f != "..") {
if (is_dir ($path . "/" . $f)) {
for ($i = 0; $i < $depth - 1; $i++) echo '<i>| </i>';
echo '<i>+-</i>';
echo "<b>$f</b>\n";
$depth++;
displaydir ($path . "/" . $f, $depth);
$depth--;
} else {
if ($sf == 1) {
for ($i = 0; $i < $depth - 1; $i++) echo '<i>| </i>';
echo '<i>+-</i>';
echo "$f\n";
}
}
}
}
closedir ($d);
}
}
displaydir ($url, 0);
?>