note 68252 modified in function.scandir by danbrown

From: Date: Thu, 28 Jan 2010 14:15:45 +0000
Subject: note 68252 modified in function.scandir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165446@lists.php.net to get a copy of this message
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 ; } ?> --was-- 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. 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 ; } http://php.net/manual/en/function.scandir.php

« previous php.notes (#165446) next »