Return true if file with given name can be created in given folder.

@param string $dir  parent dir path
@param string $name new file name
@return bool
@author Dmitry (dio) Levashov
766854
protected function allowCreate($dir, $name, $isDir = null) {
		$path = $this->joinPathCE($dir, $name);
		$perm = null;
		
		if ($this->access) {
			$perm = call_user_func($this->access, 'write', $path, $this->options['accessControlData'], $this, $isDir);			
			if ($perm !== null) {
				return !!$perm;
			}
		}
		
		$testPath = $this->separator.$this->relpathCE($path);
		
		for ($i = 0, $c = count($this->attributes); $i < $c; $i++) {
			$attrs = $this->attributes[$i];
			
			if (isset($attrs['write']) && isset($attrs['pattern']) && preg_match($attrs['pattern'], $testPath)) {
				$perm = $attrs['write'];
			} 
		}
		
		return $perm === null ? true : $perm;
	}
86925
protected function makeFilePath($folder, $name)
    {
        $folder = ltrim($folder, '\/');
        $folder = rtrim($folder, '\/');

        $name = ltrim($name, '\/');
        $name = rtrim($name, '\/');

        if ($this->packageInfo->get('type') == 'module') {
            return $this->packagesPath .DS .$this->packageInfo->get('basename') .DS .$folder .DS .$name;
        }

        return $this->packagesPath .DS .$this->packageInfo->get('basename') .DS .'src' .DS .$folder .DS .$name;
    }
294212
private function createDirIfNotExists(string $dir): bool
    {
        if (!is_dir($dir)) {
            try {
                set_error_handler(function($errno, $errstr, $errfile, $errline) {
                    restore_error_handler();
                    throw new \IvoPetkov\ObjectStorage\ErrorException($errstr, 0, $errno, $errfile, $errline);
                });
                $result = mkdir($dir, 0777, true);
                restore_error_handler();
                return (bool) $result;
            } catch (\IvoPetkov\ObjectStorage\ErrorException $e) {
                if ($e->getMessage() !== 'mkdir(): File exists') { // The directory may be just created in other process.
                    throw $e;
                }
            }
        }
        return true;
    }
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;
    }
971074
public function hasFile($name)
    {
        foreach ($this->nodes as $node) {
            if ($node->details->getFilename() == $name
                && !$node->details->isDir()
            ) {
                return true;
            }
        }
        return false;
    }
1157046
protected function isDir($dir)
    {
        try {
            $this->doChangeDir($dir);
            $this->doCdUp();

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

        return false;
    }
1272962
public function add($name,$dir){
		if ($dir === false)
			$this->request->set_sort($name);
		else
			$this->request->set_sort($name,$dir);
	}
246982
public function addPlugin($name, $dir)
    {
        Debug::enterScope($name);
        $hasPlugin = $hasZfile = false;

        try {
            $this->plugins[$name] = $this->getLocator()->locate($name . '/Plugin.php', $dir, true);
            $this->pluginPaths[$name] = dirname($this->plugins[$name]);

            $hasPlugin = true;
            $this->sourceFiles[] = $this->plugins[$name];
        } catch (\InvalidArgumentException $e) {
        }

        try {
            $zFileLocation = $this->getLocator()->locate($name . '/z.yml', $dir);
            $this->import($zFileLocation, self::PLUGIN);
            if (!isset($this->pluginPaths[$name])) {
                $this->pluginPaths[$name] = dirname($zFileLocation);
            } else if ($this->pluginPaths[$name] != dirname($zFileLocation)) {
                throw new \UnexpectedValueException(
                    "Ambiguous plugin configuration:\n"
                    . "There was a Plugin.php found in {$this->pluginPaths[$name]}, but also a z.yml at $zFileLocation"
                );
            }

            $hasZfile = true;
            $this->sourceFiles[] = $zFileLocation;
        } catch (\InvalidArgumentException $e) {
        }

        if (!$hasPlugin && !$hasZfile) {
            throw new \InvalidArgumentException("You need at least either a z.yml or a Plugin.php in the plugin path for '{$name}'");
        }
        Debug::exitScope($name);
    }
1029017
protected function mkDir($dir)
    {
        if (!file_exists($dir)) {
            mkdir($dir, self::DIR_MODE, true);
            chmod($dir, self::DIR_MODE);
        }
        if (!is_dir($dir)) {
            throw new \Exception("Failed to create directory: $dir");
        }
    }
157617
public static File createDir(String dir) {
        // create outdir
        File directory = null;
        if(dir != null) {
            directory = new File(dir);
            if(!(directory.exists() || directory.mkdir())) {
                Utils.croak("Can't find or create directory " + dir);
            }
        }
        return directory;
    }
6933
public static function create($dir, $chmod = null)
    {
        if (!file_exists($dir)) {
            if ($chmod === null) {
                $chmod = self::$defaultChmod;
            }
            mkdir($dir, $chmod, true);
            // php mkdir apply umask on the given mode, so we must to
            // do a chmod manually.
            chmod($dir, $chmod);
            return true;
        }

        return false;
    }
92647
protected function _createDirectory($dir)
    {
        $old = umask(0);
        // @codingStandardsIgnoreStart
        $result = @mkdir($dir, 0755, true);
        // @codingStandardsIgnoreEnd
        umask($old);

        if ($result) {
            $this->out('Created directory ' . $dir);

            return true;
        }

        $this->err('Failed creating directory ' . $dir);

        return false;
    }
770128
public function mkdir($dir)
    {
        if (!is_dir($dir)) {
            if (false === @mkdir($dir, $this->mode, true)) {
                $error = error_get_last();
                if (!is_dir($dir)) {
                    if ($error) {
                        throw new IOException(
                            sprintf('Failed to create "%s": %s.', $dir, $error['message']),
                            0,
                            null,
                            $dir
                        );
                    }
                    throw new IOException(sprintf('Failed to create "%s"', $dir), 0, null, $dir);
                }
            }
        }
    }
790602
function _is_dir($dir)
    {
        $dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $dir));

        $temp = &$this->dirs;
        foreach ($dirs as $dir) {
            if (!isset($temp[$dir])) {
                return false;
            }
            $temp = &$temp[$dir];
        }
    }
313762
protected function filesExist($dir, $file)
    {
        if (!file_exists($dir)) {
            return false;
        }

        $full_path = rtrim($dir, DS) . DS . ltrim($file, DS);

        try {
            $files = glob($full_path);

            $files_found = ! empty($files);
        } catch (\Exception $ex) {
            Tlog::getInstance()->addError($ex->getMessage());

            $files_found = false;
        }

        return $files_found;
    }
1221697
protected function makeFolder($dir)
    {
        if (!is_dir($dir)) {
            $parent = \dirname($dir);
            try {
                $this->makeFolder($parent);
                $this->filesystem->mkdir($dir);
                $this->filesystem->chmod($dir, $this->folderPermissions);
            } catch (IOException $e) {
                throw new \RuntimeException(sprintf('Could not create directory %s', $dir), 0, $e);
            }
        }
    }
1031523
public function mkdirP($dir)
    {
        $p = [];
        $dirs = explode(DS, $dir);
        foreach ($dirs as $name) {
            $p[] = $name;
            $path = join(DS, $p);
            if ($path === '') {
                continue;
            } elseif (! file_exists($path)) {
                mkdir($path);
            } elseif(! is_dir($path)) {
                throw new Exception("Can not mkdir, this is not directory. -> {$path}");
            }
        }
    }