Ejemplo n.º 1
0
 /**
  * The input folder will be recursively loop throught and save the folder into an array.
  * 
  * @param string $directory the root directory.
  * @param boolean $recursive sets if the function recursively fetches the directories.
  * 
  * @return array all the directories.
  */
 public static function getDirectory($directory, $recursive)
 {
     $array_items = array();
     $ignore = array('.', '..', '.svn', '.DS_Store');
     if ($handle = opendir($directory)) {
         while (false !== ($file = readdir($handle))) {
             if (!in_array($file, $ignore)) {
                 if (is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
                     if ($recursive) {
                         $array_items = array_merge($array_items, Initializer::getDirectory($directory . DIRECTORY_SEPARATOR . $file, $recursive));
                     }
                     $file = $directory . DIRECTORY_SEPARATOR . $file;
                     if (DIRECTORY_SEPARATOR == "\\") {
                         $array_items[] = preg_replace("/\\\\/si", DIRECTORY_SEPARATOR, $file);
                     } else {
                         $array_items[] = preg_replace("/\\/\\//si", DIRECTORY_SEPARATOR, $file);
                     }
                 }
             }
         }
         closedir($handle);
     }
     return $array_items;
 }