note 54454 added to ref.dir

From: Date: Tue, 05 Jul 2005 05:50:00 +0000
Subject: note 54454 added to ref.dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-91453@lists.php.net to get a copy of this message
hi all, The following code is something which shows you the tree structure of a directory ,which atually further based on he recursion(*which means if you have the folder(s) in a folder ,It ll read those also) <?php $path="./"; readdirectory($path); function readdirectory($path) { $level=getLevel($path); if (!file_exists($path)) echo "not an existing directory"; if (!is_dir($path)) echo $path." isnt a directory"; $main_dir =opendir ($path) or die("Error reading ".$path); $i=0; while ($entry=readdir($main_dir)) { if (filetype($path."/".$entry)=="dir") { if($entry!="." and $entry!=".."){ for($counter=0;$counter<=$level;$counter++){ echo "\t"; } echo "directory: ".$entry."\tLevel:".$level." \n"; readdirectory($path."/".$entry); } } else if(filetype($path."/".$entry)=="file") { for($counter=0;$counter<=$level;$counter++){ echo "\t"; } echo "File : ".$entry."\tLevel:".$level."\n"; } } } function getLevel($path) { str_replace("//","/",$path); $num=substr_count($path,"/"); return $num-1; } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.dir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54454 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54454&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54454&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54454&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54454&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54454&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54454&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54454&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91453) next »