×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: sam russo
Added: Oct 31, 2015 10:28 AM
Views: 1909
Tags: no tags
  1.  function directoryToArray($directory, $recursive,$include_directories_in_list,$include_files_in_list ) {
  2.         $array_items = array();
  3.         if ($handle = opendir($directory)) {
  4.                 while (false !== ($file = readdir($handle))) {
  5.                         if ($file != "." && $file != "..") {
  6.                                 if (is_dir($directory. "/" . $file)) {
  7.                                         if($recursive) {
  8.                                                 $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive,$include_directories_in_list,$include_files_in_list ));
  9.                                         }
  10.                                         if ($include_directories_in_list ) {                                   
  11.                                                 $file = $directory . "/" . $file;
  12.                                                 $array_items[] = preg_replace("/\/\//si", "/", $file);
  13.                                         }
  14.                                 } else {
  15.                                         if ($include_files_in_list ) {
  16.                                                 $file = $directory . "/" . $file;
  17.                                                 $array_items[] = preg_replace("/\/\//si", "/", $file);
  18.                                         }
  19.                                 }
  20.                         }
  21.                 }
  22.                 closedir($handle);
  23.         }
  24.         return $array_items;
  25. }
  26.  
  27.  
  28. // parameter1=thepath  parameter2=recursively_Y_N  parameter3=showdirectories_Y_N  parameter4=showfiles_Y_N
  29. $files = directoryToArray("/tmp/$thefile_noextension",true,true,false);
  30.