note 54454 deleted from ref.dir by sniper

From: Date: Fri, 16 Dec 2005 00:01:28 +0000
Subject: note 54454 deleted from ref.dir by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100270@lists.php.net to get a copy of this message
Note Submitter: w dot pankaj at gmail dot com ---- 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; } ?>

« previous php.notes (#100270) next »