|
Posted by J. Frank Parnell on 08/01/07 06:18
On Tue, 31 Jul 2007 21:52:03 -0700, J. Frank Parnell <pos@edgecity.ufo> wrote:
>
>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 ) ; }
//dirlist now has all dirs ,i think.Lets weed out those with no jpgs, shall we?
foreach ($dirlist as $eachdir){
$filesineach = GetDirList($eachdir, $allowedExtensions=array('jpg','JPG'));
if (count($filesineach) > 0){
$newlist[] = $eachdir;
}//if count >0
}//foreach
$dirlist = $newlist;
> return ( $dirlist ) ;
>}//func
>?>
i stuck this code in there, seems to work. Is there a Better Way?
Navigation:
[Reply to this message]
|