Posted By

klovera on 10/19/11


Tagged


Versions (?)

PHP Function: getDirectory


 / Published in: PHP
 

Returns an array of folder names contained within the passed path.

  1. function getDirectory($path){
  2.  
  3. // Directories to ignore when listing output
  4. $ignore = array( 'cgi-bin', '.', '..' );
  5.  
  6. $handle = opendir($path);
  7.  
  8. $dir_arr = array();
  9. $i = 0;
  10.  
  11. while (false !== ($dir = readdir($handle))) {
  12. if( !in_array( $dir, $ignore ) ){
  13. if (is_dir("$path/$dir")) {
  14. $dir_arr[] = $dir;
  15. }
  16. }
  17. }
  18.  
  19. closedir($handle);
  20.  
  21. return $dir_arr;
  22.  
  23. }

Report this snippet  

You need to login to post a comment.