Get full file path or its directory (with trailing slash)
@param File $file
@param boolean $includeFilename
@param integer $forcePath Forces external or internal path. Use FILE_INFO_EXTERNAL and FILE_INFO_INTERNAL constants
@return string
962083
public function getFilesystemPath(FileAbstraction $file, $includeFilename = true, $forcePath = null)
	{
		if ( ! $file instanceof FileAbstraction) {
			throw new Exception\RuntimeException('File or folder entity expected');
		}

		$path = $this->getInternalPath();

		if ($forcePath != self::FILE_INFO_INTERNAL) {
			if ($file->isPublic() || $forcePath == self::FILE_INFO_EXTERNAL) {
				$path = $this->getExternalPath();
			}
		}

		$path .= $file->getPath(DIRECTORY_SEPARATOR, $includeFilename);
		
		if ( ! $includeFilename) {
			$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
		}
	
		return $path;
	}
781560
public function getResourcePath($file = '', $admin = false)
    {
        return $this->getDir($file, $this->_sResourceDir, $admin);
    }
1087615
public static function getIncludePath($filepath)
    {
        static $_include_path = null;

        if ($_path_array === null) {
            $_include_path = explode(PATH_SEPARATOR, get_include_path());
        }

        foreach ($_include_path as $_path) {
            if (file_exists($_path . DS . $filepath)) {
                return $_path . DS . $filepath;
            }
        }
        
        return false;
    }
1175950
protected function resourcePathMatch(File $file) {
        $source_dirpath = str_replace('#', '\#', $this->sourceDir->getAbsolutePath());
        $source_dirpath = str_replace('[', '\[', $source_dirpath);
        $source_dirpath = str_replace(']', '\]', $source_dirpath);
        $source_dirpath = str_replace('(', '\(', $source_dirpath);
        $source_dirpath = str_replace(')', '\)', $source_dirpath);
        return preg_match('#^' . $source_dirpath . '/' . $this->getRegex() . '#', $file->getAbsolutePath()) ? TRUE : FALSE;
    }
949376
public static function toAbsolutePath(string $path, string $base, bool $useIncludePath = false) : string
    {
        if (self::isAbsolutePath($path)) {
            return $path;
        }

        $file = $base . DIRECTORY_SEPARATOR . $path;

        if ($useIncludePath && !file_exists($file)) {
            $includePathFile = stream_resolve_include_path($path);
            if ($includePathFile) {
                $file = $includePathFile;
            }
        }
        return $file;
    }
1309225
private function getFilePath()
    {
        $fullName = $this->fullName;
        if (substr($fullName, 0, 1) != '/') {
            $fullName = '/' . $fullName;
        }
        return $this->getSetting('storePath') . $fullName;
    }
1001339
public function getRelativePath($force = FALSE) {

		if(!isset($this->relPath) || $force) {
			$relPath = preg_replace('~^' . preg_quote(Application::getInstance()->getAbsoluteAssetsPath(), '~').'~', '', $this->path, -1, $replaced);
			$this->relPath = $replaced === 0 ? NULL : $relPath;
		}

		return $this->relPath;

	}
91065
public function determineFromFilePath($path, $includeFiles = true, $includeDirectories = true)
    {
        $path = $this->determineFilePath($path);

        $this->logger->debug(sprintf('Searching files in path: %s', $path));

        if ( ! file_exists($path) || ! is_readable($path)) {
            $this->logger->warning(sprintf('Could not read directory: %s', $path));

            return array();
        }

        $fileNames = preg_grep('/^\.+$/', scandir($path), PREG_GREP_INVERT);

        $files = array();

        if (count($fileNames) > 0) {
            natcasesort($fileNames);

            foreach ($fileNames as $fileName) {
                $fileName = $this->determineFilePath($fileName, $path);

                if ($includeFiles && is_file($fileName)) {
                    $files[] = $fileName;
                }

                if ($includeDirectories && is_dir($fileName)) {
                    $files[] = $fileName;
                }
            }
        }

        $this->logger->debug(sprintf('Found %d file(s)', count($files)));

        $this->logger->debug(sprintf('Files: %s%s', PHP_EOL, implode($files, PHP_EOL)));

        return $files;
    }
932749
private function getRealFilename(string $file): string
    {
        if (strpos($file, 'vfs://') !== false) {
            return $file;
        }

        return $this->loader->getSourceContext($file)->getPath();
    }
1010430
protected function getFilePath(string $file, ?string $extension = null, ?string $suffix = null): string
	{
		if(strpos($file, '::') === false)
		{
			// No namespace so we'll just use the default path

			$path = $this->path;
		}
		else
		{
			// The file is namespaced so we'll use the namespace path

			[$namespace, $file] = explode('::', $file, 2);

			if(!isset($this->namespaces[$namespace]))
			{
				throw new RuntimeException(vsprintf('The [ %s ] namespace does not exist.', [$namespace]));
			}

			$path = $this->namespaces[$namespace];
		}

		// Append suffix to path if needed

		if($suffix !== null)
		{
			$path .= DIRECTORY_SEPARATOR . $suffix;
		}

		// Return full path to file

		return $path . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $file) . ($extension ?? $this->extension);
	}
441387
protected function getFilePath(SplFileInfo $file): string
    {
        $location = $file->getPathName();
        $path     = $this->removeBasePath($location);

        unset($location);

        return trim(str_replace('\\', '/', $path), '/');
    }
376106
public function getPath($relativePath, $fileName = null, $ext = '.php')
    {
        $path = Path::join($this->dir, $relativePath);

        return is_null($fileName) ? $path : Path::join($path, $fileName . $ext);
    }
506807
public function getPathFromFile($filename)
	{
		$i = strrpos($filename, self::getSlash());

		if ($i!== false)
		{
			return substr($filename, 0, $i);
		}
		else
		{
			return $filename;
		}
	}
1060328
protected function getPathFile($config_name, $file_name, $file_suffix = '', $extra_dir = '', $format_psr4 = null)
    {
        $format_psr4 = $format_psr4 === null ? false : (bool) $format_psr4;
        $prefix_ns = "";

        if (!$format_psr4) {
            $prefix_ns = str_replace('\\', '/', trim($this->prefix_ns, '\\'));
        }

        $elements =
            [
                rtrim($this->prefix_dir, '/'),
                $prefix_ns,
                Inflector::studlyCaps($config_name),
                Inflector::studlyCaps(sprintf("%s_schema", $this->schema)),
                $extra_dir,
                sprintf("%s%s.php", Inflector::studlyCaps($file_name), $file_suffix)
            ];

        return join('/', array_filter($elements, function ($val) { return $val != null; }));
    }
128924
protected function getFullPath($contextPath, $targetPath): string
    {
        if ($this->filesystem->isAbsolutePath($targetPath)) {
            return $targetPath;
        }

        return rtrim($contextPath, '/\\').DIRECTORY_SEPARATOR.$targetPath;
    }
444463
private function filesWithFullPaths($dir, $include_hidden = true, $recursive = false)
    {
        $dir = $this->withSlash($dir);

        $result = [];

        if ($dirstream = opendir($dir)) {
            while (false !== ($filename = readdir($dirstream))) {
                $path = $dir . $filename;

                if ($filename != '.' && $filename != '..') {
                    if (is_dir($path)) {
                        if ($recursive) {
                            $files_from_subdir = $this->filesWithFullPaths($path, $recursive);

                            if (is_array($files_from_subdir)) {
                                $result = array_merge($result, $files_from_subdir);
                            }
                        }
                    } else {
                        if (is_file($path) || (is_link($path) && is_file(readlink($path)))) {
                            if (mb_substr($filename, 0, 1) == '.' && !$include_hidden) {
                                continue;
                            }

                            $result[] = $path;
                        }
                    }
                }
            }
        }

        closedir($dirstream);

        return $result;
    }
856149
public static function includeFileExtension($fileName, $extension)
    {
        $fileExtension = self::getFileExtension($fileName, true);

        /*
         * File has given extension?
         * Nothing to do
         */
        if ($fileExtension === strtolower($extension)) {
            return $fileName;
        }

        return sprintf('%s.%s', $fileName, $extension);
    }