note 91380 modified in function.scandir by danbrown
| From: | danbrown@php.net | Date: | Tue, 09 Jun 2009 12:59:23 +0000 |
| Subject: | note 91380 modified in function.scandir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156589@lists.php.net to get a copy of this message | ||
Hello all,
I just added a extension filter to the getDirectoryTree function, so it can filter an extension for
files in the folders/subfolders:
<?php
function getDirectoryTree( $outerDir , $x){
$dirs = array_diff( scandir( $outerDir ), Array( ".", ".." ) );
$dir_array = Array();
foreach( $dirs as $d ){
if( is_dir($outerDir."/".$d) ){
$dir_array[ $d ] = getDirectoryTree( $outerDir."/".$d , $x);
}else{
if (($x)?ereg($x.'$',$d):1)
$dir_array[ $d ] = $d;
}
}
return $dir_array;
}
$dirlist = getDirectoryTree('filmes','flv');
?>
--was--
Hello all,
I just added a extension filter to the getDirectoryTree function, so it can filter an extension for
files in the folders/subfolders:
function getDirectoryTree( $outerDir , $x){
$dirs = array_diff( scandir( $outerDir ), Array( ".", ".." ) );
$dir_array = Array();
foreach( $dirs as $d ){
if( is_dir($outerDir."/".$d) ){
$dir_array[ $d ] = getDirectoryTree( $outerDir."/".$d , $x);
}else{
if (($x)?ereg($x.'$',$d):1)
$dir_array[ $d ] = $d;
}
}
return $dir_array;
}
$dirlist = getDirectoryTree('filmes','flv');
http://php.net/manual/en/function.scandir.php