@param string $path
@param int    $mode

@return RecursiveIteratorIterator
336104
protected function getRecursiveDirectoryIterator($path, $mode = RecursiveIteratorIterator::SELF_FIRST)
    {
        return new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
            $mode
        );
    }
318710
public function createDirectory($path, $recursive = false, $mode = null)
    {
        return $this->container()->createDir($path, $recursive, $mode);
    }
1315585
public function createDirectory(&$f, $mode = 0755)
    {
        $old_umask = umask(0);
        $return = @mkdir($f->getAbsolutePath(), $mode);
        umask($old_umask);

        return $return;
    }
344130
public function mkdir($path, $mode, $options)
    {
        return $this
            ->_getOssClient($path)
            ->createObjectDir(AliyunOSS::getBucket(), $this->_getNamePart($path));
    }
601910
public function mkdirr($pathname, $mode = null)
    {
        // Check if directory already exists
        if (is_dir($pathname) || empty($pathname)) {
            return true;
        }
        // Ensure a file does not already exist with the same name
        if (is_file($pathname)) {
            return false;
        }
        // Crawl up the directory tree
        $nextPathname = substr($pathname, 0, strrpos($pathname, "/"));
        if ($this->mkdirr($nextPathname, $mode)) {
            if (!file_exists($pathname)) {
                if (is_null($mode)) {
                    return mkdir($pathname);
                } else {
                    return mkdir($pathname, $mode);
                }
            }
        } else {
            throw new \Exception (
                "intermediate mkdirr $nextPathname failed"
            );
        }
        return false;
    }
1134398
public function mkdir($path, $mode, $options)
    {
        $container = $this->getContainerFromContext($path);
        $path = $this->stripScheme($path);
        $recursive = (bool) ($options & STREAM_MKDIR_RECURSIVE);

        try {
            //need to check all parents for permissions
            $parentPath = $path;
            while ($parentPath = dirname($parentPath)) {
                try {
                    $parent = $container->nodeAt($parentPath);
                    $permissionHelper = $container->getPermissionHelper($parent);
                    if (!$permissionHelper->isWritable()) {
                        trigger_error(sprintf('mkdir: %s: Permission denied', dirname($path)), E_USER_WARNING);

                        return false;
                    }
                    if ($parent instanceof Root) {
                        break;
                    }
                } catch (NotFoundException $e) {
                    break; //will sort missing parent below
                }
            }
            $container->createDir($path, $recursive, $mode);
        } catch (FileExistsException $e) {
            trigger_error($e->getMessage(), E_USER_WARNING);

            return false;
        } catch (NotFoundException $e) {
            trigger_error(sprintf('mkdir: %s: No such file or directory', dirname($path)), E_USER_WARNING);

            return false;
        }

        return true;
    }
416578
public function scanDir($path, $fileOrDirs = self::ALL, $recursive = true)
    {
        $files = scandir($path);

        $path = $this->stripPathLastDirectorySeparator($path);

        $allFiles = [];
        foreach ($files as $file) {
            if ($file !== '.' && $file !== '..') {
                $pathToScan = $path . DIRECTORY_SEPARATOR . $file;
                if (is_dir($pathToScan)) {
                    if ($recursive) {
                        $moreFiles = $this->scanDir($pathToScan, $fileOrDirs, true);
                        $appendParents = function ($path) use ($file) {
                            return $file . DIRECTORY_SEPARATOR . $path;
                        };
                        $moreFiles = array_map($appendParents, $moreFiles);
                        $allFiles = array_merge($allFiles, $moreFiles);
                    }
                    if ($fileOrDirs & self::DIRS) {
                        $allFiles[] = (string) $file;
                    }
                } else {
                    if ($fileOrDirs & self::FILES) {
                        $allFiles[] = (string) $file;
                    }
                }
            }
        }

        return $allFiles;
    }
715066
public function addDirectory($name, $mode = 0777) {
        if (is_null($name)) {
            return $this;
        }
        $dir = $this->getChild($name);
        if (!is_dir($dir)) {
            mkdir($dir, $mode);
        }
        return new Directory($dir);
    }
713751
public static function recursive($path)
    {
        if (is_dir($path)) {
            $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
            foreach ($iterator as $file) {
                self::_deleteFile($file);
            }
            rmdir($path);
        }
    }
934384
protected function getStream($path, $mode)
    {
        switch ($mode[0]) {
            case 'r':
                $this->needsCowCheck = true;

                return $this->getFilesystem()->readStream($path);

            case 'w':
                $this->needsFlush = true;

                return fopen('php://temp', 'w+b');

            case 'a':
                return $this->getAppendStream($path);

            case 'x':
                return $this->getXStream($path);

            case 'c':
                return $this->getWritableStream($path);
        }

        return false;
    }
504635
public function createDirectory(string $path, int $mode = 0777, bool $recursive = false): bool
	{
		return mkdir($path, $mode, $recursive);
	}
699235
public function mkdir($dirs, $mode = 0777)
    {
        foreach ($this->toIterator($dirs) as $dir) {
            if (is_dir($dir)) {
                continue;
            }

            if (true !== @mkdir($dir, $mode, true)) {
                $error = error_get_last();
                if (!is_dir($dir)) {
                    // The directory was not created by a concurrent process. Let's throw an exception with a developer friendly error message if we have one
                    if ($error) {
                        throw new IOException(sprintf('Failed to create "%s": %s.', $dir, $error['message']), 0, null, $dir);
                    }
                    throw new IOException(sprintf('Failed to create "%s"', $dir), 0, null, $dir);
                }
            }
        }
    }
1142063
private function loadDirectory($path)
    {
        $directory = new RecursiveDirectoryIterator($path);
        $iterator = new RecursiveIteratorIterator($directory);
        $files = new RegexIterator($iterator, '/^[^\.](?:(?!\/\.).)+?\.php$/i');

        $fm = $this;

        foreach ($files as $file) {
            require $file->getPathName();
        }
    }
716842
public function stream_open($path, $mode, $options, &$openedPath)
    {
        $container = $this->getContainerFromContext($path);
        $path = $this->stripScheme($path);

        $mode = str_split(str_replace('b', '', $mode));

        $accessDeniedError = function () use ($path, $options) {
            if ($options & STREAM_REPORT_ERRORS) {
                trigger_error(sprintf('fopen(%s): failed to open stream: Permission denied', $path), E_USER_WARNING);
            }

            return false;
        };

        $appendMode = in_array('a', $mode);
        $readMode = in_array('r', $mode);
        $writeMode = in_array('w', $mode);
        $extended = in_array('+', $mode);

        if (!$container->hasNodeAt($path)) {
            if ($readMode || !$container->hasNodeAt(dirname($path))) {
                if ($options & STREAM_REPORT_ERRORS) {
                    trigger_error(sprintf('%s: failed to open stream.', $path), E_USER_WARNING);
                }

                return false;
            }
            $parent = $container->directoryAt(dirname($path));
            $permissionHelper = $container->getPermissionHelper($parent);
            if (!$permissionHelper->isWritable()) {
                return $accessDeniedError();
            }
            $parent->addFile($container->factory()->getFile(basename($path)));
        }

        $file = $container->nodeAt($path);

        if ($file instanceof Link) {
            $file = $file->getDestination();
        }

        if (($extended || $writeMode || $appendMode) && $file instanceof Directory) {
            if ($options & STREAM_REPORT_ERRORS) {
                trigger_error(sprintf('fopen(%s): failed to open stream: Is a directory', $path), E_USER_WARNING);
            }

            return false;
        }

        if ($file instanceof Directory) {
            $dir = $file;
            $file = $container->factory()->getFile('tmp');
            $file->chmod($dir->mode());
            $file->chown($dir->user());
            $file->chgrp($dir->group());
        }

        $permissionHelper = $container->getPermissionHelper($file);

        $this->currentlyOpenedFile = new FileHandler();
        $this->currentlyOpenedFile->setFile($file);

        if ($extended) {
            if (!$permissionHelper->isReadable() || !$permissionHelper->isWritable()) {
                return $accessDeniedError();
            }
            $this->currentlyOpenedFile->setReadWriteMode();
        } elseif ($readMode) {
            if (!$permissionHelper->isReadable()) {
                return $accessDeniedError();
            }
            $this->currentlyOpenedFile->setReadOnlyMode();
        } else { // a or w are for write only
            if (!$permissionHelper->isWritable()) {
                return $accessDeniedError();
            }
            $this->currentlyOpenedFile->setWriteOnlyMode();
        }

        if ($appendMode) {
            $this->currentlyOpenedFile->seekToEnd();
        } elseif ($writeMode) {
            $this->currentlyOpenedFile->truncate();
            clearstatcache();
        }

        $openedPath = $file->path();

        return true;
    }
271815
public static function create($path, $mode = 0775, $recursive = true): bool
    {
        return (is_dir($path) || !(!@mkdir($path, $mode, $recursive) && !is_dir($path))) && is_writable($path);
    }
753998
public static function setCacheMode($mode = 1)
    {
        $instance = self::getInstance();
        if ($mode == 1) {
            $instance->_options['mode'] = 1;
        } else {
            $instance->_options['mode'] = 2;
        }

        return $instance;
    }
1212470
public function getFilesWithExtension($path, $ext = 'php')
    {
        if (is_dir($path)) {
            return new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
            ), '/^.+\.'.$ext.'$/i', RecursiveRegexIterator::GET_MATCH);
        } else {
            return [];
        }
    }