note 94899 added to function.scandir

From: Date: Tue, 01 Dec 2009 20:34:33 +0000
Subject: note 94899 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-163463@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.197 Probable Submitter: 216.221.92.71 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/94899 Del: integrated -- https://master.php.net/note/delete/94899/integrated Del: useless -- https://master.php.net/note/delete/94899/useless Del: bad code -- https://master.php.net/note/delete/94899/bad+code Del: spam -- https://master.php.net/note/delete/94899/spam Del: non-english -- https://master.php.net/note/delete/94899/non-english Del: in docs -- https://master.php.net/note/delete/94899/in+docs Del: other reasons-- https://master.php.net/note/delete/94899 Reject -- https://master.php.net/note/reject/94899 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163463) next »