Creates a filesystem directory query.

@param string $path  The directory path.
@param int    $flags One of the {@see FilesystemIterator} flags.<br>
Default = KEY_AS_PATHNAME | CURRENT_AS_FILEINFO | SKIP_DOTS
@return static
963086
static function from ($path, $flags = 4096)
  {
    try {
      return new static (new FilesystemIterator($path, $flags));
    }
    catch (\Exception $e) {
      // Convert UnexpectedValueException to another type to prevent problems with some error handlers.
      throw new \InvalidArgumentException($e->getMessage ());
    }
  }
269310
public function putContents($path, $data, $flags = 0)
    {
        $fullPath = $this->concatPaths($path); //todo remove after changing the params

        if ($this->checkCreateFile($fullPath) === false) {
            throw new Error('Permission denied for '. $fullPath);
        }

        $res = (file_put_contents($fullPath, $data, $flags) !== FALSE);
        if ($res && function_exists('opcache_invalidate')) {
            @opcache_invalidate($fullPath);
        }

        return $res;
    }
427055
public function mkdir($path)
    {
        $info = $this->info($path);
        if ($info->isDir()) {
            return $this;
        }

        if (!mkdir($info->getStreamUrl(), $this->dirMode, true)) {
            throw new RuntimeException(sprintf(
                'Failed to create directory "%s": %s',
                $path, $this->getLastPhpError()
            ));
        }

        return $this;
    }
331799
public static function mkDir($path)
    {
        if (file_exists($path)) {
            return false;
        }

        $umask = umask();
        $res = @mkdir($path, Constants::FILESYSTEM_DIR_PERMISSIONS_DEFAULT, true);
        if ($res === false) {
            throw new RuntimeException('Can not create directory "' . $path . '" - no permissions.');
        }
        umask($umask);

        return $res;
    }
723784
public function find(string $pattern, int $flags = 0): Collection
    {
        $files = glob($this->path.'/'.$pattern, $flags);
        foreach ($files as $index => $file) {
            if (is_dir($file)) {
                $files[$index] = new self($file);
            } else {
                $files[$index] = new File($file);
            }
        }

        return new Collection($files);
    }
261534
public function mkdir($path)
	{
		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			if (@ftp_mkdir($this->conn, $path) === false)
			{
				throw new FilesystemException(__METHOD__ . 'Bad response.');
			}

			return true;
		}

		// Send change directory command and verify success
		if (!$this->_putCmd('MKD ' . $path, 257))
		{
			throw new FilesystemException(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 257].  Path sent: %3$s', __METHOD__, $this->response, $path)
			);
		}

		return true;
	}
33187
public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
    {
        if (!empty($path)) {
            $path = '['.$path.']';
        }

        return new self(
            sprintf(
                'File mapping drivers must have a valid directory path, '.
                'however the given path "%s" seems to be incorrect!',
                $path
            )
        );
    }
351594
public function create($path)
	{
		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			// Turn passive mode on
			if (@ftp_pasv($this->conn, true) === false)
			{
				throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.');
			}

			$buffer = fopen('buffer://tmp', 'r');

			if (@ftp_fput($this->conn, $path, $buffer, FTP_ASCII) === false)
			{
				fclose($buffer);

				throw new FilesystemException(__METHOD__ . 'Bad response.');
			}

			fclose($buffer);

			return true;
		}

		// Start passive mode
		if (!$this->_passive())
		{
			throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.');
		}

		if (!$this->_putCmd('STOR ' . $path, array(150, 125)))
		{
			@ fclose($this->dataconn);

			throw new FilesystemException(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 150 or 125].  Path sent: %3$s', __METHOD__, $this->response, $path)
			);
		}

		// To create a zero byte upload close the data port connection
		fclose($this->dataconn);

		if (!$this->_verifyResponse(226))
		{
			throw new FilesystemException(
				sprintf('%1$s: Transfer failed.  Server response: %2$s [Expected: 226].  Path sent: %3$s', __METHOD__, $this->response, $path)
			);
		}

		return true;
	}
1179972
protected function makeDirectory($path)
    {
        if (!is_dir(dirname($path))) {
            mkdir(dirname($path), 0777, true);
        }

        return $path;
    }
32368
public static function mkdir(string $path)
    {
        if (!is_dir($path))
        {
            mkdir($path, self::$dir_mode, true);
        }
    }
6384
public function dir($path, $createMissing = false)
    {
        if (! $this->adapter->isAbsolute($path)) {
            $path = $this->rootPath . $path;
        }
        if (! $createMissing && ! $this->isDir($path, true)) {
            throw new FilesystemException("Cannot find the directory '{$path}'");
        }
        return new Directory($path, $this->adapter);
    }
169189
private function getDirectoryIterator($path)
    {
        $nodes = new \DirectoryIterator($path);
        $dirs = [];

        foreach ($nodes as $dir) {
            if (!$dir->isDir()) {
                continue;
            }

            if ($dir->isDot()) {
                continue;
            }

            $dirs[hexdec($dir->getFilename())] = $dir->getPathname();
        }

        krsort($dirs);

        return new \ArrayIterator($dirs);
    }
617205
public static function lastModifiedFolder($path)
    {
        $last_modified = 0;

        /** @var UniformResourceLocator $locator */
        $locator = Grav::instance()['locator'];
        $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
        if ($locator->isStream($path)) {
            $directory = $locator->getRecursiveIterator($path, $flags);
        } else {
            $directory = new \RecursiveDirectoryIterator($path, $flags);
        }
        $filter  = new RecursiveFolderFilterIterator($directory);
        $iterator = new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::SELF_FIRST);

        /** @var \RecursiveDirectoryIterator $file */
        foreach ($iterator as $dir) {
            $dir_modified = $dir->getMTime();
            if ($dir_modified > $last_modified) {
                $last_modified = $dir_modified;
            }
        }

        return $last_modified;
    }
682834
public function url_stat($path, $flags)
    {
        $content = $this->getContent($this->resolvePath(vfsStream::path($path)));
        if (null === $content) {
            if (($flags & STREAM_URL_STAT_QUIET) != STREAM_URL_STAT_QUIET) {
                trigger_error(' No such file or directory: ' . $path, E_USER_WARNING);
            }

            return false;

        }

        $fileStat = array('dev'     => 0,
                          'ino'     => 0,
                          'runtimeEnvironment'    => $content->getType() | $content->getPermissions(),
                          'nlink'   => 0,
                          'uid'     => $content->getUser(),
                          'gid'     => $content->getGroup(),
                          'rdev'    => 0,
                          'size'    => $content->size(),
                          'atime'   => $content->fileatime(),
                          'mtime'   => $content->filemtime(),
                          'ctime'   => $content->filectime(),
                          'blksize' => -1,
                          'blocks'  => -1
                    );
        return array_merge(array_values($fileStat), $fileStat);
    }
659689
public function addWatch($path, $cb, $flags = null)
    {
        $path = realpath($path);
        if (!isset($this->files[$path])) {
            $this->files[$path] = [];
            if ($this->inotify) {
                $this->descriptors[inotify_add_watch($this->inotify, $path, $flags ?: IN_MODIFY)] = $path;
            }
        }
        $this->files[$path][] = $cb;
        Timer::setTimeout('fileWatcher');
        return true;
    }
454664
public function findFiles(string $pattern, int $flags = 0): FileCollection
    {
        $files = glob($this->path.'/'.$pattern, $flags);
        foreach ($files as $index => $file) {
            if (is_file($file)) {
                $files[$index] = new File($file);
            } else {
                unset($files[$index]);
            }
        }

        return new FileCollection($files);
    }
382243
protected function createDirectory(string $path, int $permissions = 0755)
    {
        if (!is_dir($path)) {
            $this->info("Creating directory '{$path}'", OutputInterface::VERBOSITY_VERBOSE);

            mkdir($path, $permissions, true);
        }
    }