Check if passed path exists or try to create it.
Return false if it fails to create it or if a file (and not a dir) passed as argument.
@param string $filePath
@param string $modeMask default '0755'
@return bool
494078
public static function checkDirExistOrCreate(string $filePath, string $modeMask = '0755') : bool
    {
        if (self::isDirSafe($filePath)) {
            return true;
        }

        //controllo adesso che non sia un file
        if (FileHelper::fileExistsSafe($filePath)) {
            return false;
        }

        return mkdir($filePath, $modeMask, true) && self::isDirSafe($filePath);
    }
851919
public function isFileAllowed($filePath)
    {
        $filePath = realpath($filePath);
        foreach ($this->allowedImageFolders as $key => $nextFolder) {
            if (0 === strpos($filePath, $nextFolder)) {
                return $key;
            }
        }

        return false;
    }
1241260
public static function create($path = false, $mode = 0777) {

        if($path && !self::isFolder(dirname($path)) && self::isWritable(dirname($path))) {

            mkdir($path, $mode);

            if(Folder::isFolder($path)) {

                return true;
            }
        } 

        return false;
    }
137410
public function compressFile (string $filePath) : bool
    {
        $compressor = $this->getCompressor();

        if (null === $compressor)
        {
            return false;
        }

        $process = new Process(\array_merge($compressor, [$filePath]));
        $process->run();
        return $process->isSuccessful();
    }
962776
protected function checkFilePath($filePath)
	{
	    $filePath = rtrim($filePath, '/\\');
	    if (!is_dir($filePath)) {
			mkdir($filePath, 0755, true);
		}
        
		if (!is_writable($filePath)) {
			throw new \RuntimeException(sprintf('The base cache path `%s` is not writable.', $filePath));
		}

		return true;
	}
51656
public function readFileFunc($filepath)
    {
        /** @var UniformResourceLocator $locator */
        $locator = $this->grav['locator'];

        if ($locator->isStream($filepath)) {
            $filepath = $locator->findResource($filepath);
        }

        if ($filepath && file_exists($filepath)) {
            return file_get_contents($filepath);
        }

        return false;
    }
441289
public function make($mode = 0777) {
		if (!$this->exists() && !@mkdir($this->pathname, $mode, true)) {
			throw new FileException(sprintf('Failed to create directory "%s"', $this->pathname));
		}
	}
1116195
static function changeFilePermissions( $filepath )
    {
        if ( !file_exists( $filepath ) )
            return false;
        $ini = eZINI::instance( 'image.ini' );
        $perm = $ini->variable( "FileSettings", "ImagePermissions" );
        $success = false;
        $oldmask = umask( 0 );
        if ( !chmod( $filepath, octdec( $perm ) ) )
            eZDebug::writeError( "Chmod $perm $filepath failed", __METHOD__ );
        else
            $success = true;
        umask( $oldmask );
        return $success;
    }
449075
public static function ensureExists($path = null, $mode = self::DEFAULT_UNIX_CHMOD_DIRECTORIES, $recursive = true)
    {
        if (is_null($path)) {
            return null;
        }
        if (file_exists($path) && is_dir($path)) {
            return true;
        }
        return self::create($path, $mode, $recursive);
    }
352568
protected function verifyChecksum(string $checksum, string $filePath) : bool
    {
        // Skip if checksum is empty.
        if (empty($checksum)) {
            return true;
        }

        return $checksum === $this->getServerChecksum($filePath);
    }
708746
public function setFilepath(Path $filepath)
    {
        if ($this->filepath === null) {
            $this->filepath = $filepath;
        } else {
            $this->filepath->append($filepath);
        }
    }
1042955
public function delete($filePath)
    {
        $relativePath = $this->fs->makePathRelative($filePath, $this->root);
        if (preg_match('!(^|/)\.\.!', $relativePath)) {
            throw new \RuntimeException("{$relativePath} does not seem to be managed by the filemanager");
        }
        if ($this->fs->exists($filePath)) {
            $this->fs->remove($filePath);
            $this->dispatchEvent(ResourceEvent::DELETED, $filePath);
            return true;
        }
        return false;
    }
509015
protected function isWritable($filePath)
    {
        return !is_dir($filePath)
            &&
            (file_exists($filePath) ? is_writable($filePath) : is_writable(dirname($filePath)));
    }
1298916
public function createDirectory($dirPath)
    {
      if (! $this->fs->exists($dirPath))
      {
        $this->fs->mkdir($dirPath);
      }
    }
429196
public function setFilePath($filePath)
    {
        Assert::stringNotEmpty($filePath, 'The factory file path must be a non-empty string. Got: %s');

        $this->setDirectory(Path::getDirectory($filePath));
        $this->setFileName(Path::getFilename($filePath));

        return $this;
    }
485947
protected function isMessagesExcluded($filePath)
    {
        if (empty($this->messagesIncluded)) {
            return false;
        }

        $filePath = str_replace(DIRECTORY_SEPARATOR, '/', $filePath);

        $localeDirSeparatorPosition = strpos($filePath, '/');
        $filePath = substr($filePath, $localeDirSeparatorPosition);
        $filePath = ltrim($filePath, '/');
        $filePath = substr($filePath, 0, -4);

        if (in_array($filePath, $this->messagesIncluded)) {
            return false;
        }

        return true;
    }
1338078
public function mkdir(string $path, int $mode, int $options): bool
    {
        $umask = vfsStream::umask();
        if (0 < $umask) {
            $permissions = $mode & ~$umask;
        } else {
            $permissions = $mode;
        }

        $path = $this->resolvePath(vfsStream::path($path));
        if (null !== $this->getContent($path)) {
            trigger_error('mkdir(): Path vfs://' . $path . ' exists', E_USER_WARNING);
            return false;
        }

        if (null === self::$root) {
            self::$root = vfsStream::newDirectory($path, $permissions);
            return true;
        }

        $maxDepth = count(explode('/', $path));
        $names    = $this->splitPath($path);
        $newDirs  = $names['basename'];
        $dir      = null;
        $i        = 0;
        while ($dir === null && $i < $maxDepth) {
            $dir     = $this->getContent($names['dirname']);
            $names   = $this->splitPath($names['dirname']);
            if (null == $dir) {
                $newDirs = $names['basename'] . '/' . $newDirs;
            }

            $i++;
        }

        if (null === $dir
          || $dir->getType() !== vfsStreamContent::TYPE_DIR
          || $dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {
            return false;
        }

        $recursive = ((STREAM_MKDIR_RECURSIVE & $options) !== 0) ? (true) : (false);
        if (strpos($newDirs, '/') !== false && false === $recursive) {
            return false;
        }

        vfsStream::newDirectory($newDirs, $permissions)->at($dir);
        return true;
    }