note 94899 deleted from function.scandir by danbrown

From: Date: Wed, 02 Dec 2009 15:08:45 +0000
Subject: note 94899 deleted from function.scandir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163498@lists.php.net to get a copy of this message
Note Submitter: Svetoslav Marinov ---- Hi, Here is a modification of Dustin's function from 27-Oct-2009 08:08 My modification doesn't return a multi dimensional array. The values are full path to the file and it includes folders which have at least one file. <?php var_dump(getDirectoryTree('.')); function getDirectoryTree( $outerDir, $filters = array() ){ $dirs = array_diff( scandir( $outerDir ), array_merge( Array( ".", ".." ), $filters ) ); $dir_array = Array(); foreach( $dirs as $d ) { $dir_array = array_merge($dir_array, is_dir($outerDir."/".$d) ? getDirectoryTree( $outerDir . "/" . $d, $filters ) : (array) $dir_array[ $d ] = $outerDir . "/" . $d); } return $dir_array; } ?> // Output: array(9) { [0]=> string(3) "./1" [1]=> string(3) "./a" [2]=> string(14) "./adir/aaa.txt" [3]=> string(24) "./adir/aaaaadir/test.txt" [4]=> string(14) "./adir/zzz.txt" [5]=> string(3) "./b" [6]=> string(3) "./c" [7]=> string(9) "./dir.php" [8]=> string(10) "./dir2.php" } Svetoslav Marinov http://devcha.com http://seofilter.com

« previous php.notes (#163498) next »