note 50249 deleted from ref.dir by sniper

From: Date: Fri, 16 Dec 2005 00:01:12 +0000
Subject: note 50249 deleted from ref.dir by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100267@lists.php.net to get a copy of this message
Note Submitter: bardoartifex at yahoo dot com dot br ---- Hi, I worked a lot with some usefull recursive functions and one "C pointer-like" approach using PHP. The result is a small code to read directories and files to generate an associative array. I hope if this will be usefull for you as was to me. (Ah, sorry by my poor english!) There it's the code: function &walkThroughDir ($path,&$filelist) { if (!is_dir($path)) return NULL; $resdir = @opendir ($path) or die("Error reading ".$path); // It's the secret for this recursive function $ret = &$filelist; while ( ($entry=readdir($resdir))!==false ) { if ( is_dir($path."/".$entry)=="dir" ) { //if it's a directory... if ($entry!="." and $entry!="..") {//do not use ./ or ../ // Call himself using the same result array walkThroughDir($path."/".$entry,$ret); }//if } else { // if it is not a dir, read the filenames $ret[$path][] = $entry; }//if }//while closedir($resdir); return $ret; }//walkThroughDir This function will generate something alike: Array ( [/Library/WebServer/Documents/component/test/subtest] => Array ( [0] => linuxitscool.php ) [/Library/WebServer/Documents/component/test] => Array ( [0] => macosxrulez.php [1] => unixrulez.php ) [/Library/WebServer/Documents/dev/component] => Array ( [0] => Component.h.php [1] => Component.pkg.php ) )

« previous php.notes (#100267) next »