note 68252 deleted from function.scandir by danbrown

From: Date: Thu, 28 Jan 2010 14:16:03 +0000
Subject: note 68252 deleted from function.scandir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165447@lists.php.net to get a copy of this message
Note Submitter: malmsteenforce at tlen dot pl ---- This function is recursive version of scandir, it scans all directories inside given directory. For instance : if we give path './dir1/' as argument , function will find also /dir1/dir2/file etc. - everything what`s inside given directory. <?php function scandir_recursive($path) { if (!is_dir($path)) return 0; $list=array(); $directory = @opendir("$path"); // @-no error display while ($file= @readdir($directory)) { if (($file<>".")&&($file<>"..")) { $f=$path."/".$file; $f=preg_replace('/(\/){2,}/','/',$f); //replace double slashes if(is_file($f)) $list[]=$f; if(is_dir($f)) $list = array_merge($list ,scandir_recursive($f)); //RECURSIVE CALL } } @closedir($directory); return $list ; } ?>

« previous php.notes (#165447) next »