Ensures the given path exists.

@param string $path    any path
@param string $baseDir the base directory where the directory is created
($path must still contain the full path, $baseDir
is only used for unix permissions)

@throws Exception
174874
protected function makeDirectory($path, $baseDir = null)
    {
        if (is_dir($path) === true) {
            return;
        }

        if ($this->chmod === null) {
            $chmod = 0777;
        } else {
            $chmod = $this->chmod;
        }

        $retries = 3;
        while ($retries --) {
            @mkdir($path, $chmod, true);
            if (is_dir($path)) {
                break;
            }
            usleep(20);
        }

        // enforce the correct mode for all directories created
        if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {
            $path    = strtr(str_replace($baseDir, '', $path), '\\', '/');
            $folders = explode('/', trim($path, '/'));
            foreach ($folders as $folder) {
                $baseDir .= $folder . DIRECTORY_SEPARATOR;
                if (!chmod($baseDir, $chmod)) {
                    throw new Exception('Unable to chmod ' . "$baseDir to $chmod: " . print_r(error_get_last(), true));
                }
            }
        }
    }
86652
public function checkPath($path = null)
    {
        if (is_null($path)) {
            $path = $this->getDir();
        }

        $real_path = realpath($path);
        if (!$real_path) {
            $real_path = realpath(dirname($path));
        }
        $upload_path = realpath($this->getUploadPath());

        if (strcasecmp($real_path, $upload_path) > 0) {
            return true;
        } else {
            throw new \Exception("Directory is not in the upload path", 403);
        }
    }
1322437
protected function createDir($path)
    {
        $dir = pathinfo($path, PATHINFO_DIRNAME);
        if (!is_dir($dir)) {
            if (@mkdir($dir, 0755, true) === false) {
                throw new \Exception('Error in dir creation');
            }
        }
    }
894988
protected function makeDirectory($path)
    {
        if (! $this->fileHelper->exists($path)) {
            $this->fileHelper->makeDirectory($path, 0777, true, true);
        }
    }
289545
public boolean isDirectory(String path) {
		path = path.replace('/', File.separatorChar);
		return new File(baseDir, path).isDirectory();
	}
20443
protected function realSetPath($path, $relative)
    {
        if (!is_string($path) || !$this->validatePath($path, $relative)) {
            throw new \InvalidArgumentException(
                'Invalid path; use relative() for relative paths'
            );
        }
        $this->path = $path;
    }
753188
public function getFilePath( string$filePath, string$path=null ):string
	{
		if( !isset($this->basePath) )
			{ throw new \Exception('BasePath musbe set.'); }

		if( !strlen($filePath) )
			{ throw new \Exception('FilePath cannot be empty.'); }

		if( '/'===$filePath{0} ){
			if( is_null($path) )
				{ return $filePath; }
			else
				{ return $this->basePath.$filePath; }
		}else{
			if( !strlen($path) )
				{ return $this->basePath.'/'.$filePath; }
			elseif( '/'===substr($path,-1) )
				{ return $path.$filePath; }
			else
				{ return $path.'/'.$filePath; }
		}

	}
216090
public function base_path($path = null)
    {
        return empty($path) ? $this->path : $this->path . $path;
    }
700969
protected static function getExistingPath($path, $webDir, $fallbackPath = null)
    {
        return file_exists($webDir.'/'.$path)
            ? realpath($webDir.'/'.$path)
            : (null !== $fallbackPath ? $fallbackPath : $path);
    }
83528
private function createDir($path)
    {
        if (!is_dir($path)) {
            $success = mkdir($path, 0775, true);
            if (!$success) {
                throw new \Exception("Cannot create folder {$path}. Check file system permissions.");
            }
        }
    }
1038080
private function checkBaseDir($reader, array $base)
    {
        if (!isset($base[$reader]) || !is_dir(dirname(app_path()) . '/' . $base[$reader])) {
            throw new \RuntimeException('Either a basedir is not set or basedir is not a directory');
        }
    }
1184246
public function setResourcePath($path)
    {
        $escapedPath = rtrim($path, '/');
        if (!file_exists($escapedPath)) {
            throw new Exception(sprintf(
                "The path '%s' to resources' folder does not exist!",
                $escapedPath
            ));
        }

        $this->resourcePath = $escapedPath;
    }
719187
protected function set_base_path( $base_path ) {
        if ( ! is_string( $base_path ) ) {
            throw new InvalidArgumentException( 'Invalid argument. `$base_path` must be string.' );
        }

        if ( strpos( $base_path, '.php' ) !== false ) {
            $base_path = preg_replace( '/[^\/]*$/', '', $base_path );
        }

        $this->base_path = rtrim( $base_path, '/' );
    }
1131187
public function allowDirectory($path)
	{
		if (is_array($path))
			foreach ($path as $dir)
				$this->allowedDirectories[realpath($dir)] = true;
		else
			$this->allowedDirectories[realpath($path)] = true;
	}
924588
protected function realpath($path)
    {
        if ($path === '') {
            return $this->baseDir;
        }

        if ($path[0] === '/' || $path[1] === ':') {
            return $path;
        }

        return $this->baseDir . '/' . $path;
    }
96885
public function file($path)
    {
        if (!isset($this->_baseDir)) {
            throw new App\Exception('Base directory not set');
        }
        return $this->_baseDir->file($path);
    }
948014
public static function setBaseDir($path)
    {
        $path = realpath(rtrim($path, '/\\ '));
        if ($path === false) {
            throw new \InvalidArgumentException("cat`t get real path: seems like path does`t exists: $path");
        }

        return static::$baseDir = $path;
    }