|
Posted by J. Frank Parnell on 08/01/07 04:52
Hi there,
I got this directory tree listing function somewhere, it works great,
but I want it to only list directories that do have one or more .jpgs
inside. I tried getting a list of each dir's contents and doing
if count($dir) > 0
But something not working out for me.
<?php
// $path : path to browse
// $maxdepth : how deep to browse (-1=unlimited)
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined
function searchdir( $path , $maxdepth = -1 , $mode = "FULL" , $d = 0 )
{
if ( substr ( $path , strlen ( $path ) - 1 ) != '/' )
{ $path .= '/' ; }
$dirlist = array () ;
if ( $mode != "FILES" )
{ $dirlist[] = $path ; }
if ( $handle = opendir ( $path ) ){
while ( false !== ( $file = readdir ( $handle ) ) ){
if ( $file != '.' && $file != '..' ){
$file = $path . $file ;
if ( ! is_dir ( $file ) ) {
if ( $mode != "DIRS" ){$dirlist[] = $file ;} //if ( $mode NOT "DIRS" )
}elseif ( ($d >=0) AND ($d < $maxdepth || $maxdepth < 0) ) {
$result = searchdir ( $file . '/' , $maxdepth , $mode , $d + 1 ) ;
$dirlist = array_merge ( $dirlist , $result ) ;
}//elsif
}//if ( $file != '.' && $file != '..' )
}// while reading
closedir ( $handle ) ;
}// if( $handle = opendir ( $path )
if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
return ( $dirlist ) ;
}//func
?>
thanks
Navigation:
[Reply to this message]
|