Get all subdirectories of directory

@param string $dir directory location
@param boolean $subdir include subdirectories of subdirectory
@return array
771904
public static function getAllSubdirectories($dir, $subdir = false) {
        $path = '';
        $stack[] = $dir;
        while ($stack) {
            $thisdir = array_shift($stack);
            if ($dircont = scandir($thisdir)) {
                $i = 0;
                while (isset($dircont[$i])) {
                    if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
                        $current_file = "{$thisdir}/{$dircont[$i]}";
                        if (is_dir($current_file)) {
                            $temp = explode("/", $current_file);
                            $path[$temp[count($temp) - 1]] = "{$thisdir}/{$dircont[$i]}";

                            if ($subdir === true)
                                $stack[] = $current_file;
                        }
                    }
                    $i++;
                }
            }
        }
        return $path;
    }
1277526
protected function _scanDir($dir)
    {
        $dir = new Folder($dir);
        $contents = $dir->read(true, true);
        if (empty($contents[1])) {
            return [];
        }
        $shells = [];
        foreach ($contents[1] as $file) {
            if (substr($file, -4) !== '.php') {
                continue;
            }
            $shells[] = substr($file, 0, -4);
        }

        return $shells;
    }
654116
protected function getDir($dir, $excludeSubFolders = [])
    {
        $directories = [];
        if (file_exists($dir)) {
            $excludeDir = array_merge(['.', '..', '.gitignore'], $excludeSubFolders);
            $directory = array_diff(scandir($dir), $excludeDir);

            foreach ($directory as $d) {
                if (is_dir($dir . '/' . $d)) {
                    $directories[] = $d;
                }
            }

        }

        return $directories;
    }
213159
public function directories($directory)
    {
        $this->checkDirectory($directory);

        $directories = array_map(function ($dir) use ($directory) {
            return [
                'name' => str_replace("$directory/", '', $dir),
                'path' => $dir,
            ];
        }, $this->disk()->directories($directory));

        return DirectoryCollection::make($directories)
            ->exclude($this->getExcludedDirectories());
    }
45547
public function files($directory)
    {
        $directory = ltrim($directory, "/");
        $files = array();

        $dirIterator = new RecursiveDirectoryIterator($this->pathRoot.$directory);
        $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
        
        foreach ($iterator as $file) {
            if (filetype($file) == 'file') {
                $files[] = strval($file);
            }
        }
        
        return $files;
    }
1249478
public function getDirs($dir)
    {
        $dirArr = array();
        $files = ftp_rawlist($this->link, $dir);
        foreach ($files as $v) {
            $file = ltrim(strrchr($v, ' '), ' ');
            $path = "{$dir}/{$file}";
            if (preg_match('/^d/', $v)) {
                if (in_array($file, array('.', '..'))) {
                    continue;
                }
                if (preg_match('/^[a-zA-z0-9]+$/', $file)) { //file check
                    $dirArr[] = $path;
                    $dirArr = array_merge($dirArr, self::getDirs($path));
                }
            }
        }
        return $dirArr;
    }
282616
static public function getFiles( $dir, $recursive = false )
    {
        $files = [];
        if ( ( $dh = opendir( $dir ) ) ) {
            while ( ( $file = readdir( $dh ) ) !== false ) {
                if ( is_file( $dir . '/' . $file ) ) {
                    $files[] = $file;
                }
                if ( $recursive && ( $file !== '.' && $file !== '..' && is_dir( $dir . '/' . $file ) ) ) {
                    $files = array_merge( $files, self::getFiles( $dir . DS . $file, true ) );
                }
            }
            closedir( $dh );
        }
        return $files;
    }
114292
static function findSubitems( $dir, $types = false, $fullPath = false, $includeHidden = false, $excludeItems = false )
    {
        if ( !$types )
            $types = 'dfl';
        $dirArray = array();
        if ( $handle = @opendir( $dir ) )
        {
            while ( ( $element = readdir( $handle ) ) !== false )
            {
                if ( $element === '.' || $element === '..' )
                    continue;
                if ( !$includeHidden && $element[0] === '.' )
                    continue;
                if ( $excludeItems && preg_match( $excludeItems, $element ) )
                    continue;
                if ( strpos( $types, 'd' ) === false && is_dir( $dir . '/' . $element ) )
                    continue;
                if ( strpos( $types, 'l' ) === false && is_link( $dir . '/' . $element ) )
                    continue;
                if ( strpos( $types, 'f' ) === false && is_file( $dir . '/' . $element ))
                    continue;
                if ( $fullPath )
                {
                    if ( is_string( $fullPath ) )
                        $dirArray[] = $fullPath . '/' . $element;
                    else
                        $dirArray[] = $dir . '/' . $element;
                }
                else
                    $dirArray[] = $element;
            }
            @closedir( $handle );
        }
        return $dirArray;
    }
1257721
public static function get_include_files( $directory, $exclude_underscore = false ) {
		$return = [
			'files'       => [],
			'directories' => [],
		];

		if ( ! is_dir( $directory ) ) {
			return $return;
		}

		$directory_iterator = new \DirectoryIterator( $directory );

		foreach ( $directory_iterator as $file ) {
			if ( $file->isDot() ) {
				continue;
			}

			if ( $file->isDir() ) {
				$return['directories'][] = $file->getPathname();
				continue;
			}

			if ( 'php' !== $file->getExtension() ) {
				continue;
			}

			if ( $exclude_underscore ) {
				if ( 0 === strpos( $file->getBasename(), '_' ) ) {
					continue;
				}
			}

			$return['files'][] = $file->getPathname();
		}

		return $return;
	}
471083
private ArrayList<String> getFiles(String dir, String subDir) {
    ArrayList<String> files = new ArrayList<>();
    String fullDir = subDir == null ? dir : dir + File.separator + subDir;
    File[] listOfFiles = (new File(fullDir)).listFiles();
    if (listOfFiles != null) {
      for (File file : listOfFiles) {
        String fullName = subDir == null ? file.getName() : subDir + File.separator + file.getName();
        if (file.isFile()) {
          files.add(fullName);
        } else if (file.isDirectory()) {
          files.addAll(getFiles(dir, fullName));
        }
      }
    }
    return files;
  }
1200120
public function getAction($subdir, $name)
    {
        $file = $this->logDir.$subdir.DIRECTORY_SEPARATOR.$name.'.json';

        if (file_exists($file)) {
            return new Response(file_get_contents($file));
        }

        return new JsonResponse(['log' => 'no file found']);
    }
766022
public function getFilesList($dir)
	{
		$list = [];
		$iterator = Aws\recursive_dir_iterator($dir);
		foreach ($iterator as $filename) {
			$list[] = $filename;
		}
		return $list;
	}
1243926
protected function getFileList($dir)
	{
		$finder = new Finder();
		$iterator = $finder
			->ignoreDotFiles(false)
			->files()
			->sortByName()
			->in($dir)
		;

		$files = array();
		foreach ($iterator as $file)
		{
			/** @var \SplFileInfo $file */
			$files[] = str_replace(DIRECTORY_SEPARATOR, '/', substr($file->getPathname(), strlen($dir) + 1));
		}

		return $files;
	}
383130
public function ls($dir = '')
    {
        $dir = ($dir == '' ? getcwd() : $dir);
        $this->errorHandler->start();
        if (($files = $this->driver->scandir($dir, 0, $this->resource)) !== false) {

            return $files;
        }
        $this->errorHandler->stop();

        return false;
    }
473147
static function getDir($dir = '.', $ext = NULL) {

		if($dir != '') {
			$dir = rtrim($dir, '/').'/';
		}
		try {
			$i = new \DirectoryIterator($dir);
		} catch (\Exception $e) {
			return false;
		}

		$files = array();

		foreach($i as $file) {
			$fn = $file->getFileName();
			if(!$file->isDot() && $file->isFile() && substr($fn, 0, 1) !== '.') {
				if(!isset($ext) || preg_match("~$ext\$~", $fn)) {
					$files[] = $fn;
				}
			}
		}

		return $files;
	}
1134856
public static function isSubDirectoryOf(array $subDir, array $parentDir) : bool
    {
        foreach ($parentDir as $index => $dir) {
            if (!isset($subDir[$index]) || $dir !== $subDir[$index]) {
                return false;
            }
        }
        return true;
    }
504920
public function getSubDirs($depth = 0)
	{
		$dirs = [];

		$contents = $this->hasAdapterOrFail()->adapter->listContents($this->getPath(), false);
		foreach ($contents as $item)
		{
			if ($item->isDir())
			{
				$thisDir = new stdClass();
				$thisDir->depth = $depth;
				$thisDir->subdirs = $item->getSubDirs($depth+1);
				$thisDir->name = $item->getDisplayName();
				$thisDir->path = $item->getPath();
				$dirs[] = $thisDir;
			}
		}
		return $dirs;
	}