ezEngine  Release 25.03
ezPathUtils Class Reference

Contains Helper functions to work with paths. More...

#include <PathUtils.h>

Static Public Member Functions

static bool IsPathSeparator (ezUInt32 c)
 Returns whether c is any known path separator.
 
static bool IsValidFilenameChar (ezUInt32 uiCharacter)
 Checks if a given character is allowed in a filename (not path!) More...
 
static bool ContainsInvalidFilenameChars (ezStringView sPath)
 Checks every character in the string with IsValidFilenameChar() More...
 
static const char * FindPreviousSeparator (const char *szPathStart, const char *szStartSearchAt)
 Searches for the previous path separator before szStartSearchAt. Will return nullptr if it reaches szPathStart before finding any separator.
 
static bool HasAnyExtension (ezStringView sPath)
 Checks whether the given path has any file extension.
 
static bool HasExtension (ezStringView sPath, ezStringView sExtension)
 Checks whether the path ends with the given file extension. szExtension may or may not start with a dot. The check is case insensitive. More...
 
static ezStringView GetFileExtension (ezStringView sPath, bool bFullExtension=false)
 Returns the file extension of the given path. Will be empty, if the path does not end with a proper extension. The dot (.) is not included. More...
 
static ezStringView GetFileName (ezStringView sPath, bool bRemoveFullExtension=false)
 Returns the file name of a path, excluding the path and extension. More...
 
static ezStringView GetWithoutExtension (ezStringView sPath, bool bRemoveFullExtension=false)
 Returns the path, excluding the file extension.
 
static ezStringView GetFileNameAndExtension (ezStringView sPath)
 Returns the substring that represents the file name including the file extension. More...
 
static ezStringView GetFileDirectory (ezStringView sPath)
 Returns the directory of the given file, which is the substring up to the last path separator. More...
 
static bool IsAbsolutePath (ezStringView sPath)
 Returns true, if the given path represents an absolute path on the current OS.
 
static bool IsRelativePath (ezStringView sPath)
 Returns true, if the given path represents a relative path on the current OS.
 
static bool IsRootedPath (ezStringView sPath)
 A rooted path starts with a colon and then names a file-system data directory. Rooted paths are used as 'absolute' paths within the ezFileSystem.
 
static void GetRootedPathParts (ezStringView sPath, ezStringView &ref_sRoot, ezStringView &ref_sRelPath)
 Splits the passed path into its root portion and the relative path. More...
 
static ezStringView GetRootedPathRootName (ezStringView sPath)
 Special case of GetRootedPathParts that returns the root of the input path and discards the relative path.
 
static void MakeValidFilename (ezStringView sFilename, ezUInt32 uiReplacementCharacter, ezStringBuilder &out_sFilename)
 Creates a valid filename (not path!) using the given string by replacing all disallowed characters. More...
 
static bool IsSubPath (ezStringView sPrefixPath, ezStringView sFullPath)
 Checks whether sFullPath starts with sPrefixPath.
 
static bool IsSubPath_NoCase (ezStringView sPrefixPath, ezStringView sFullPath)
 Checks whether sFullPath starts with sPrefixPath. Case insensitive.
 

Static Public Attributes

static const char OsSpecificPathSeparator = EZ_PLATFORM_PATH_SEPARATOR
 The path separator used by this operating system.
 

Detailed Description

Contains Helper functions to work with paths.

Only functions that require read-only access to a string are provided here All functions that require to modify the path are provided by ezStringBuilder. Many functions return ezStringView's, which will always be strict sub-strings of their input data. That allows that these functions can work without any additional memory allocations.

Member Function Documentation

◆ ContainsInvalidFilenameChars()

bool ezPathUtils::ContainsInvalidFilenameChars ( ezStringView  sPath)
static

Checks every character in the string with IsValidFilenameChar()

This is a basic check, only because each character passes the test, it does not guarantee that the full string is a valid path.

Test:
Not tested yet

◆ GetFileDirectory()

ezStringView ezPathUtils::GetFileDirectory ( ezStringView  sPath)
static

Returns the directory of the given file, which is the substring up to the last path separator.

If the path already ends in a path separator, and thus points to a folder, instead of a file, the unchanged path is returned. "path/to/file" -> "path/to/" "path/to/folder/" -> "path/to/folder/" "filename" -> "" "/file_at_root_level" -> "/"

◆ GetFileExtension()

ezStringView ezPathUtils::GetFileExtension ( ezStringView  sPath,
bool  bFullExtension = false 
)
static

Returns the file extension of the given path. Will be empty, if the path does not end with a proper extension. The dot (.) is not included.

If bFullExtension is false, a file named "file.a.b.c" will return "c". If bFullExtension is true, a file named "file.a.b.c" will return "a.b.c".

◆ GetFileName()

ezStringView ezPathUtils::GetFileName ( ezStringView  sPath,
bool  bRemoveFullExtension = false 
)
static

Returns the file name of a path, excluding the path and extension.

If the path already ends with a path separator, the result will be empty.

◆ GetFileNameAndExtension()

ezStringView ezPathUtils::GetFileNameAndExtension ( ezStringView  sPath)
static

Returns the substring that represents the file name including the file extension.

Returns an empty string, if sPath already ends in a path separator, or is empty itself.

◆ GetRootedPathParts()

void ezPathUtils::GetRootedPathParts ( ezStringView  sPath,
ezStringView ref_sRoot,
ezStringView ref_sRelPath 
)
static

Splits the passed path into its root portion and the relative path.

":MyRoot\file.txt" -> root = "MyRoot", relPath="file.txt" ":MyRoot\folder\file.txt" -> root = "MyRoot", relPath = "folder\file.txt" ":\MyRoot\folder\file.txt" -> root = "MyRoot", relPath = "folder\file.txt" ":/MyRoot\folder\file.txt" -> root = "MyRoot", relPath = "folder\file.txt" If the path is not rooted, then root will be an empty string and relPath is set to the full input path.

◆ HasExtension()

bool ezPathUtils::HasExtension ( ezStringView  sPath,
ezStringView  sExtension 
)
static

Checks whether the path ends with the given file extension. szExtension may or may not start with a dot. The check is case insensitive.

HasExtension("file.txt", "txt") -> true HasExtension("file.txt", ".txt") -> true HasExtension("file.a.b", ".b") -> true HasExtension("file.a.b", "a.b") -> true HasExtension("file.a.b", ".a.b") -> true HasExtension("file.a.b", "file.a.b") -> false

◆ IsValidFilenameChar()

bool ezPathUtils::IsValidFilenameChar ( ezUInt32  uiCharacter)
static

Checks if a given character is allowed in a filename (not path!)

Test:
Not tested yet

◆ MakeValidFilename()

void ezPathUtils::MakeValidFilename ( ezStringView  sFilename,
ezUInt32  uiReplacementCharacter,
ezStringBuilder out_sFilename 
)
static

Creates a valid filename (not path!) using the given string by replacing all disallowed characters.

Note that path separators in the given string will be replaced as well! Asserts that replacementCharacter is an allowed character.

See also
IsValidFilenameChar()

The documentation for this class was generated from the following files: