Ejemplo n.º 1
0
 /**
  * Returns an array of files in a directory.
  *
  * It returns the full path ie including the original directory's path.
  * If including_dirs is set to true it will also return the folders included in the path.
  *
  * <code>
  * \bbn\file\dir::get_files("C:\Docs\Test"); //Returns ['C:/DocsTest/file.txt', 'C:/DocsTest/file.doc']
  * \bbn\file\dir::get_files("C:\Docs\Test", 1); //Returns ['C:/DocsTest/test1', 'C:/DocsTest/test2', 'C:/DocsTest/file.txt', 'C:/DocsTest/file.doc']
  * </code>
  * 
  * @param string $dir The directory path.
  * @param bool $including_dirs If set to true it will also return the folders included in the path.
  * 
  * @return array|false 
  */
 public static function get_files($dir, $including_dirs = false)
 {
     $dir = self::clean($dir);
     if (is_dir($dir)) {
         $files = [];
         $fs = scandir($dir);
         foreach ($fs as $f) {
             if ($f !== '.' && $f !== '..') {
                 if ($including_dirs) {
                     array_push($files, self::cur($dir . '/') . $f);
                 } else {
                     if (is_file($dir . '/' . $f)) {
                         array_push($files, self::cur($dir . '/') . $f);
                     }
                 }
             }
         }
         \bbn\tools::sort($files);
         return $files;
     }
     return false;
 }