note 36471 modified in ref.dir by didou
| From: | didou@php.net | Date: | Sat, 11 Oct 2003 11:32:33 +0000 |
| Subject: | note 36471 modified in ref.dir by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58240@lists.php.net to get a copy of this message | ||
get a list of files and directories recursivelly without the use of global variables.
the difference between this one and piccaso at gmx dot net's, is that this one returns files
inside the subdirectories as well (with full path) :
function recursive_listdir($base) {
static $filelist = array();
static $dirlist = array();
if(is_dir($base)) {
$dh = opendir($base);
while (false !== ($dir = readdir($dh))) {
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir
!== '..') {
$subbase = $base ."/". $dir;
$dirlist[] = $subbase;
$subdirlist = recursive_listdir($subbase);
} elseif(is_file($base ."/". $dir) && $dir !== '.'
&& $dir !== '..') {
$filelist[] = $base ."/". $dir;
}
}
closedir($dh);
}
$array['dirs'] = $dirlist;
$array['files'] = $filelist;
return $array;
}
--was--
testing get a list of files and directories recursivelly without the use of global variables.
the difference between this one and piccaso at gmx dot net's, is that this one returns files
inside the subdirectories as well (with full path) :
function recursive_listdir($base) {
static $filelist = array();
static $dirlist = array();
if(is_dir($base)) {
$dh = opendir($base);
while (false !== ($dir = readdir($dh))) {
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir
!== '..') {
$subbase = $base ."/". $dir;
$dirlist[] = $subbase;
$subdirlist = recursive_listdir($subbase);
} elseif(is_file($base ."/". $dir) && $dir !== '.'
&& $dir !== '..') {
$filelist[] = $base ."/". $dir;
}
}
closedir($dh);
}
$array['dirs'] = $dirlist;
$array['files'] = $filelist;
return $array;
}
http://www.php.net/manual/en/ref.dir.php