Ensure the base directory exists

@param string $dir

@return bool
968712
protected function ensureDirectory($dir)
    {
        if ($this->filesystem->isDirectory($dir)) {
            return true;
        }

        if (!@$this->filesystem->makeDirectory($dir)) {
            throw new RuntimeException("Cannot create base directory '$dir'");
        }

        return true;
    }
988259
private function createDirectory($dir)
    {
        if (file_exists($dir)) {
            return $this;
        }
        if (false === @mkdir($dir, 0777, true)) {
            throw new \RuntimeException(sprintf('Unable to create directory "%s"', $dir));
        }
        return $this;
    }
935977
public function ensureDirectory($dirname)
    {
        $dirname = (string) $dirname;
        if ($dirname !== '' && !$this->has($dirname)) {
            $this->createDir($dirname, []);
        }
    }
137333
private function exists($dir, $template)
    {
        $path = $dir.DIRECTORY_SEPARATOR.$template;

        return file_exists($path) ? $path : false;
    }
341822
private function mkdir_p( $dir )
    {
        // create parent directories
        $dirElements = explode( '/', $dir );
        if ( count( $dirElements ) == 0 )
            return true;

        $result = true;
        $currentDir = $dirElements[0];

        if ( $currentDir != '' && !file_exists( $currentDir ) && !eZDir::mkdir( $currentDir, false ) )
            return false;

        for ( $i = 1; $i < count( $dirElements ); ++$i )
        {
            $dirElement = $dirElements[$i];
            if ( strlen( $dirElement ) == 0 )
                continue;

            $currentDir .= '/' . $dirElement;

            if ( !file_exists( $currentDir ) && !eZDir::mkdir( $currentDir, false ) )
                return false;

            $result = true;
        }

        return $result;
    }
54185
protected function processDir($dir) {
    $dir = $this->replacePattern($dir);
    // The absolute path has to be calculated relative to the configuration file
    if (Path::isRelative($dir)) {
      $dir = Path::makeAbsolute($dir, dirname($this->configFile));
    }
    return rtrim($dir, '/');
  }
895251
public static function existsDirWritable($dir)
    {
        if (!is_dir($dir)) {
            return false;
        }

        $testFile = $dir . "/write_file_" . time() . ".txt";
        if (!@file_put_contents($testFile, "WRITABLE TEST")) {
            return false;
        } else {
            @unlink($testFile);
        }

        return true;
    }
383130
public function ls($dir = '')
    {
        $dir = ($dir == '' ? getcwd() : $dir);
        $this->errorHandler->start();
        if (($files = $this->driver->scandir($dir, 0, $this->resource)) !== false) {

            return $files;
        }
        $this->errorHandler->stop();

        return false;
    }
717020
public function isIn($dir) {
		if(!$this->formatPath($dir))
			return false;
		return strpos($this->formatPath($this->src()), $this->formatPath($dir)) === 0;
	}
90185
public static function _dir(string $folder) : bool
  {
    if (is_dir($folder)) {
      return true;
    }

    mkdir($folder, 0777, true);
    return false;
  }
14582
public static function isDir($path)
    {
        return (self::isPhar($path) === true) ? file_exists($path) : is_dir($path);
    }
659361
public function isExcludedDirectory($directory)
    {
        foreach ($this->getExcludedDirectories() as $pattern) {
            if (Str::is($pattern, $directory)) return true;
        }

        return false;
    }
280087
protected function _rmdir( $dir )
    {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator( $dir,
                RecursiveDirectoryIterator::CURRENT_AS_FILEINFO |
                RecursiveDirectoryIterator::SKIP_DOTS
            ),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        $result = true;

        foreach ( $iterator as $info )
        {
            $path = $info->getPathname();

            switch ( true )
            {
                case $info->isFile():
                case $info->isLink():
                    $result = $result && @ unlink( $path );
                    break;

                case $info->isDir():
                    $result = $result && @ rmdir( $path );
                    break;
            }

        }

        return $result && @ rmdir( $dir );
    }
82817
public static function rmDir($dir)
    {
        if (!file_exists($dir)) {
            return true;
        }
        if (!is_dir($dir)) {
            return unlink($dir);
        }
        foreach (scandir($dir) as $item) {
            if ($item == '.' || $item == '..') {
                continue;
            }
            if (!Paths::rmDir($dir . DIRECTORY_SEPARATOR . $item)) {
                return false;
            }

        }
        return rmdir($dir);
    }
365293
public function isdir( $path )
	{
		return in_array( basename( $path ), $this->fs->directories( dirname( $path ) ) );
	}
979108
public function fileExists($directory = null)
    {
        $directory = ($directory) ?: $this->fileDirectory;
        $fileExists = file_exists($this->publicDirectory . $directory . $this->file);
        return $fileExists;
    }
1157046
protected function isDir($dir)
    {
        try {
            $this->doChangeDir($dir);
            $this->doCdUp();

            return true;
        } catch (\Exception $ex) {
            return false;
        }

        return false;
    }