Create a directory if necessary

@param   string  $path
@param   int     $mode
@param   bool    $recursive
@return  bool
762782
public static function create($path = null, $mode = self::DEFAULT_UNIX_CHMOD_DIRECTORIES, $recursive = true)
    {
        if (is_null($path)) {
            return null;
        }
        return mkdir($path, Filesystem::getOctal($mode), $recursive);
    }
1177706
public static function mkdir($dst, $mode = null, $recursive = false)
    {
        if ($mode === null) {
            $mode = 0777;
        }
        $prevDir = dirname($dst);
        if ($recursive && !is_dir($dst) && !is_dir($prevDir)) {
            self::mkdir(dirname($dst), $mode, true);
        }
        $res = mkdir($dst, $mode);
        @chmod($dst, $mode);
        return $res;
    }
17804
public function create($filePath = null, $mode = 'wb')
    {
        $filePath = isset($filePath) ? $filePath : $this->filePath;
        $dir = dirname($filePath);

        if ( ! is_writable($dir)) {
            if ( ! file_exists($dir)) {
                mkdir($dir, 0777, true);
            }
        }

        if ( ! $fp = @fopen($filePath, $mode)) {
            return false;
        }

        parent::__construct($filePath);

        return $fp;
    }
1315585
public function createDirectory(&$f, $mode = 0755)
    {
        $old_umask = umask(0);
        $return = @mkdir($f->getAbsolutePath(), $mode);
        umask($old_umask);

        return $return;
    }
822278
public function createFolder(String $path, Int $mode = 0777, Bool $recursive = true) : Bool
    {
        if( @ssh2_sftp_mkdir($this->connect, $path, $mode, $recursive) )
        {
            return true;
        }
        else
        {
            throw new FolderAllreadyException(NULL, $path);
        }
    }
640844
public static function removeFolder($path, $recursive = true)
    {
        if (is_dir($path)) {
            if ($recursive) {
                $objects = scandir($path);
                foreach ($objects as $object) {
                    if ($object != "." && $object != "..") {
                        if (filetype($path . DS . $object) == "dir") {
                            self::removeFolder($path . DS . $object);
                        } else {
                            unlink($path . DS . $object);
                        }
                    }
                }
                reset($objects);
                rmdir($path);
            } else {
                rmdir($path);
            }
        }
    }
858154
public static function chmod($files, $mode, $umask = 0000, $recursive = false)
    {
        self::ensureFileSystem()->chmod($files, $mode, $umask, $recursive);
    }
524189
public function createDir($path, $recursive = false, $mode = null)
    {
        $parentPath = dirname($path);
        $name = basename($path);

        try {
            $parent = $this->directoryAt($parentPath);
        } catch (NotFoundException $e) {
            if (!$recursive) {
                throw new NotFoundException(sprintf('createDir: %s: No such file or directory', $parentPath));
            }
            $parent = $this->createDir($parentPath, $recursive, $mode);
        }

        $parent->addDirectory($newDirectory = $this->factory()->getDir($name));

        if (!is_null($mode)) {
            $newDirectory->chmod($mode);
        }

        return $newDirectory;
    }
227764
public function mkdir($path, $permission = null, $recursive = false)
    {
        $fullPath = $this->concatPaths($path);

        if (file_exists($fullPath) && is_dir($path)) {
            return true;
        }

        $defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();

        if (!isset($permission)) {
            $permission = (string) $defaultPermissions['dir'];
            $permission = base_convert($permission, 8, 10);
        }

        try {
            $result = mkdir($fullPath, $permission, true);

            if (!empty($defaultPermissions['user'])) {
                $this->getPermissionUtils()->chown($fullPath);
            }

            if (!empty($defaultPermissions['group'])) {
                $this->getPermissionUtils()->chgrp($fullPath);
            }
        } catch (\Exception $e) {
            $GLOBALS['log']->critical('Permission denied: unable to create the folder on the server - '.$fullPath);
        }

        return isset($result) ? $result : false;
    }
1357135
public function mkdir($directory, $recursive = false)
    {
        if (!$recursive or $this->isDir($directory)) {
            return $this->ftp->mkdir($directory);
        }

        $result = false;
        $pwd = $this->ftp->pwd();
        $parts = explode('/', $directory);

        foreach ($parts as $part) {
            if (!@$this->ftp->chdir($part)) {
                $result = $this->ftp->mkdir($part);
                $this->ftp->chdir($part);
            }
        }

        $this->ftp->chdir($pwd);

        return $result;
    }
1734
public static function safeMkdir($dir, $mode = 0777, $recursive = true) {
		if (! \is_dir ( $dir ))
			return \mkdir ( $dir, $mode, $recursive );
		return true;
	}
336104
protected function getRecursiveDirectoryIterator($path, $mode = RecursiveIteratorIterator::SELF_FIRST)
    {
        return new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
            $mode
        );
    }
1036114
public function mkdir($path, $mode, $options) {
		$parts = explode('://', $path, 2);

		$this->scheme	= $parts[0];
		$this->id		= rtrim($parts[1], '/') . '/';
		$this->db		= self::$config[$this->scheme]['db'];
		$this->table	= self::$config[$this->scheme]['table'];

		$this->entry = [
			'id'	=> $this->id,
			'type'	=> 'dir',
			'data'	=> '',
			'ctime'	=> date('Y-m-d H:i:s', time()),
			'mtime'	=> date('Y-m-d H:i:s', time()),
		];

		//$this->db->insert($this->table, $this->entry);
		return false;
	}
1257906
protected function changePermission(string $path, $mode = 0755, bool $recursively = false): void
    {
        $filesystem = $this->getContainer()['files'];

        $filesystem->chmod($path, $mode);

        if ($recursively === false) {
            return;
        }

        $lists = $filesystem->allFiles($path);

        $ignoredPath = function ($dir) {
            return (\substr($dir, -3) === '/..' || \substr($dir, -2) === '/.');
        };

        // this is to check if return value is just a single file,
        // avoiding infinite loop when we reach a file.
        if ($lists !== [$path]) {
            foreach ($lists as $dir) {
                // Not a file or folder, ignore it.
                if (! $ignoredPath($dir)) {
                    $this->changePermission($dir, $mode, true);
                }
            }
        }
    }
569875
private function createFile(string $path, string $mode = null, int $options = null)
    {
        $names = $this->splitPath($path);
        if (empty($names['dirname']) === true) {
            if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
                trigger_error('File ' . $names['basename'] . ' does not exist', E_USER_WARNING);
            }

            return false;
        }

        /** @var vfsStreamDirectory|null $dir */
        $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR);
        if (null === $dir) {
            if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
                trigger_error('Directory ' . $names['dirname'] . ' does not exist', E_USER_WARNING);
            }

            return false;
        } elseif ($dir->hasChild($names['basename']) === true) {
            if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
                trigger_error('Directory ' . $names['dirname'] . ' already contains a director named ' . $names['basename'], E_USER_WARNING);
            }

            return false;
        }

        if (self::READ === $mode) {
            if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
                trigger_error('Can not open non-existing file ' . $path . ' for reading', E_USER_WARNING);
            }

            return false;
        }

        if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {
            if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
                trigger_error('Can not create new file in non-writable path ' . $names['dirname'], E_USER_WARNING);
            }

            return false;
        }

        /** @var vfsStreamFile $file */
        $file = vfsStream::newFile($names['basename'])->at($dir);

        return $file;
    }
668939
function rmkdir($path, $mode = 0755) {
        return is_dir($path) || ( $this->rmkdir(dirname($path), $mode) && $this->_mkdir($path, $mode) );
    }
835997
public static function mkdir(string $pathname, int $mode = 0777, bool $recursive = true, $context = null)
    {
        if (empty($pathname) || is_file($pathname)) {
            return false;
        }
        if (is_dir($pathname)) {
            return true;
        }
        return is_resource($context) ? mkdir($pathname, $mode, $recursive, $context) : mkdir($pathname, $mode, $recursive);
    }