note 92679 modified in function.opendir by danbrown

From: Date: Tue, 04 Aug 2009 17:10:26 +0000
Subject: note 92679 modified in function.opendir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159100@lists.php.net to get a copy of this message
Hopefully this helps someone else. Returns a list of all the files in the directory and any subdirectories. Excludes files/folders that are in the $exempt array. Can modifiy it so files aren't passed by reference fairly easily. <?php function getFiles($directory,$exempt = array('.','..','.ds_store','.svn'),&$files = array()) { $handle = opendir($directory); while(false !== ($resource = readdir($handle))) { if(!in_array(strtolower($resource),$exempt)) { if(is_dir($directory.$resource.'/')) array_merge($files, self::getFiles($directory.$resource.'/',$exempt,$files)); else $files[] = $directory.$resource; } } closedir($handle); return $files; } ?> --was-- <?php function getFiles($directory,$exempt = array('.','..','.ds_store','.svn'),&$files = array()) { $handle = opendir($directory); while(false !== ($resource = readdir($handle))) { if(!in_array(strtolower($resource),$exempt)) { if(is_dir($directory.$resource.'/')) array_merge($files, self::getFiles($directory.$resource.'/',$exempt,$files)); else $files[] = $directory.$resource; } } closedir($handle); return $files; } ?> Hopefully that helps someone else. Returns a list of all the files in the directory and any subdirectories. Excludes files/folders that are in the $exempt array. Can modifiy it so files aren't passed by reference fairly easily. http://php.net/manual/en/function.opendir.php

« previous php.notes (#159100) next »