note 88006 modified in function.scandir by danbrown

From: Date: Tue, 06 Jan 2009 00:39:44 +0000
Subject: note 88006 modified in function.scandir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148868@lists.php.net to get a copy of this message
If I'm remembering my CS classes right... this would be the 'bare bones' recursive method to extract directories and files... <?php function getDirectoryTree( $outerDir ){ $dirs = array_diff( scandir( $outerDir ), Array( ".", ".." ) ); $dir_array = Array(); foreach( $dirs as $d ){ if( is_dir($outerDir."/".$d) ) $dir_array[ $d ] = getDirectoryTree( $outerDir."/".$d ); else $dir_array[ $d ] = $d; } return $dir_array; } ?> --was-- If I'm remembering my CS classes right... this would be the 'bare bones' recursive method to extract directories and files... function getDirectoryTree( $outerDir ){ $dirs = array_diff( scandir( $outerDir ), Array( ".", ".." ) ); $dir_array = Array(); foreach( $dirs as $d ){ if( is_dir($outerDir."/".$d) ) $dir_array[ $d ] = getDirectoryTree( $outerDir."/".$d ); else $dir_array[ $d ] = $d; } return $dir_array; } http://php.net/manual/en/function.scandir.php

« previous php.notes (#148868) next »