Gets a list of directory objects with a depth for walking a directory structure

@param		int	$depth	How deep you currently are since beginning to walk
@return	array
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;
	}
993448
public function getDirectoryParts(): array
    {
        return $this->myAboveBaseLevel === 0 ? $this->myDirectoryParts : array_merge(array_fill(0, $this->myAboveBaseLevel, '..'), $this->myDirectoryParts);
    }
543747
public function populateTree($depth = null)
    {
        /** @var ActiveRecord|MaterializedPathBehavior $nodes */
        $nodes = $this
            ->getDescendants($depth)
            ->indexBy($this->keyAttribute)
            ->all();
        $relates = [];
        foreach ($nodes as $key => $node) {
            $parentKey = $node->getParentKey();
            if (!isset($relates[$parentKey])) {
                $relates[$parentKey] = [];
            }
            $relates[$parentKey][] = $node;
        }
        $nodes[$this->owner->{$this->keyAttribute}] = $this->owner;
        foreach ($relates as $key => $children) {
            $nodes[$key]->populateRelation('children', $children);
        }
        return $this->owner;
    }
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;
	}
1257681
public function files($directory, $recursive = false)
    {
        $result     = [];
        $recursive  = boolval($recursive);

        if ( ! $this->isDirectory($directory)) return [];

        $items = new FilesystemIterator($directory);

        foreach ($items as $item) {
            if ($item->isFile()) {
                $result[]       = $item->getPathname();
            } elseif ($recursive && $item->isDir() && ! $item->isLink()) {
                $subFiles       = $this->files($item->getPathname(), $recursive);
                foreach ($subFiles as $file) {
                    $result[]   = $file;
                }
            }
        }

        return $result;
    }
657522
public function getFiles($dir){
		$dir = self::normalizePath($dir);
	    $files = scandir($dir);
		$results = [];
	    foreach($files as $key => $value){
		    $path = self::normalizePath(self::combinePath($dir, $value));
	        if(!is_dir($path)) {
	        	$results[] = $path;
	        } else if($value != "." && $value != "..") {
	            $results = array_merge($results, getDirContents($path));
	        }
	    }
	    return $results;
	}
1058314
private function flattenCallback($array, $depth = INF): array
    {
        $depth = (int) $depth;

        return array_reduce($array, function ($result, $item) use ($depth) {
            $item = $item instanceof self ? $item->all() : $item;

            if (! is_array($item)) {
                return array_merge($result, [$item]);
            } elseif ($depth === 1) {
                return array_merge($result, array_values($item));
            }

            return array_merge($result, self::flattenCallback($item, $depth - 1));
        }, []);
    }
764534
public static function getFolderTreeIds($folderId, $depth = 1)
    {
        $result = \is_array($folderId) ? $folderId : [ $folderId ];

        if ($depth > 1) {
            $folders = self::create()
                ->filterByParent($folderId, Criteria::IN)
                ->withColumn('id')
                ->find();

            foreach ($folders as $folder) {
                $result = array_merge(
                    $result,
                    self::getFolderTreeIds($folder->getId(), $depth - 1)
                );
            }
        }

        return $result;
    }
1267378
public function getParents($depth = null)
    {
        /** @var \yii\db\ActiveQuery|MaterializedPathQueryTrait $query */
        $query = $this->owner->find();
        return $query->parentsOf($this->owner, $depth);
    }
480284
protected function getHierarchicalChoicesAttributes($nodes, $depth = 0)
    {
        $choices = array();
        $lastNode = end($nodes);
        foreach ($nodes as $node) {
            $choices[$node['node']['nodeId']] = array(
                'data-depth' => $depth,
                'data-last' => $node === $lastNode,
            );
            if (array_key_exists('child', $node)) {
                $choices = array_merge($choices, $this->getHierarchicalChoicesAttributes($node['child'], $depth + 1));
            }
        }

        return $choices;

    }
955985
protected function listDirectoryContents($directory, $recursive = true)
    {
        $result = [];
        $connection = $this->getConnection();
        $location = $this->prefix($directory);
        $listing = $connection->rawlist($location);

        if ($listing === false) {
            return [];
        }

        foreach ($listing as $filename => $object) {
            if (in_array($filename, ['.', '..'])) {
                continue;
            }

            $path = empty($directory) ? $filename : ($directory.'/'.$filename);
            $result[] = $this->normalizeListingObject($path, $object);

            if ($recursive && isset($object['type']) && $object['type'] === NET_SFTP_TYPE_DIRECTORY) {
                $result = array_merge($result, $this->listDirectoryContents($path));
            }
        }

        return $result;
    }
394237
public function directories($directory)
    {
        $directories = [];

        foreach (Finder::create()->in($directory)->directories()->depth(0)->sortByName() as $dir) {
            $directories[] = $dir->getPathname();
        }

        return $directories;
    }
537717
public function findAll(array $locations = [])
    {
        if (empty($locations)) {
            $locations = $this->lookupPaths;
        }

        $finder = new Finder;
        $finder->directories()->depth(0)->sortByName()->in($locations);

        return iterator_to_array($finder, true);
    }
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;
    }
1168992
public function getSubdirectories()
    {
        $directories = array();
        if ($directoryHandle = opendir($this->m_sPath)) {
            while (false !== ($sFileName = readdir($directoryHandle))) {
                if (
                    $sFileName != "."
                        && $sFileName != ".."
                        && (is_dir($this->m_sPath . "/" . $sFileName))) {

                    array_push($directories, $sFileName);
                }
            }
        }
        sort($directories);
        return $directories;
    }
1220182
public function directories($directory)
    {
        $directories = array();

        foreach (Finder::create()->in($directory)->directories()->ignoreVCS(false)->ignoreDotFiles(false)->ignoreUnreadableDirs(false)->depth(0) as $dir)
        {
            $directories[] = $dir->getPathname();
        }

        return $directories;
    }
161893
private function findGitDirectories() : array
    {
        $finderGit = $this->finderFactory->build();
        $finderGit->in($this->environment->getRootDirectory())->depth('> 0')->path('/.git$/');
        $rawExcludePathsByFileByGit = $this->finderToRealPathConverter->finderToArrayOfPaths($finderGit);
        return array_map('dirname', $rawExcludePathsByFileByGit);
    }