note 35316 added to ref.dir

From: Date: Wed, 27 Aug 2003 12:53:36 +0000
Subject: note 35316 added to ref.dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-55173@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/ref.dir.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35316 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35316&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35316&report=yes

« previous php.notes (#55173) next »