Filepath¶
| Spice | |
|---|---|
FilePath struct¶
Represents a path to a file or directory on the local file system
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct an empty file path
ctor¶
| Spice | |
|---|---|
Construct a file path from a raw string
Parameters
| Name | Type | Description |
|---|---|---|
pathStr |
string |
Path string |
ctor¶
| Spice | |
|---|---|
Construct a file path from a String
Parameters
| Name | Type | Description |
|---|---|---|
pathStr |
const String& |
Path string |
Methods¶
replaceSeparator¶
| Spice | |
|---|---|
Replace every path separator in the path with the given one
Parameters
| Name | Type | Description |
|---|---|---|
separator |
char |
Separator to use |
makeGeneric¶
| Spice | |
|---|---|
Convert the path to use the generic (UNIX) path separator
makeNative¶
| Spice | |
|---|---|
Convert the path to use the native path separator of the current platform
isEmpty¶
| Spice | |
|---|---|
Checks if the filepath is empty
Returns: bool — Is the filepath empty
toString¶
| Spice | |
|---|---|
Returns the content of the filepath without modifying.
Returns: string — The content of the filepath
toGenericString¶
| Spice | |
|---|---|
Returns the content of the filepath using the UNIX path separator.
Returns: string — The content of the filepath using the UNIX path separator
toNativeString¶
| Spice | |
|---|---|
Returns the content of the filepath using the native path separator.
Returns: string — The content of the filepath using the native path separator
getFileName¶
| Spice | |
|---|---|
Returns the parent directory of the file or directory.
Example:
In: /home/user/file.txt
Out: file.txt
Returns: String — The parent directory of the file or directory
getParentDir¶
| Spice | |
|---|---|
Returns the parent directory of the file or directory.
Example:
In: /home/user/file.txt
Out: /home/user
In: file.txt
Out: (empty)
Returns: String — The parent directory of the file or directory
getBaseName¶
| Spice | |
|---|---|
Returns the base name of the file.
Example:
In: /home/user/file.txt
Out: file
Returns: String — The base name of the file
getExtension¶
| Spice | |
|---|---|
Returns the extension of the file.
Example:
In: /home/user/file.txt
Out: txt
Returns: String — The extension of the file
replaceExtension¶
| Spice | |
|---|---|
Replaces the current file extension with the given new one. If the file has no extension, the new one is appended. An empty new extension removes the current one.
Example:
In: /home/user/file.txt
Out: /home/user/file.spice
Parameters
| Name | Type | Description |
|---|---|---|
newExtension |
string |
New file extension, with or without leading dot |
exists¶
| Spice | |
|---|---|
Checks if the file or directory exists.
Returns: bool — True if the file or directory exists, false otherwise
hasRootPath¶
| Spice | |
|---|---|
Checks whether the path is absolute (starts with the UNIX path separator).
Returns: bool — True if the path is absolute
isAbsolute¶
| Spice | |
|---|---|
Checks whether the path is absolute. Alias for hasRootPath().
Returns: bool — True if the path is absolute
hasParentDirComponent¶
| Spice | |
|---|---|
Checks whether any component of the path (before any symlink resolution) is exactly '..'. This is a cheap, purely lexical check meant to reject an obviously-escaping path before doing any filesystem work; it does not catch a symlink that resolves outside the intended root (use canonical()/equivalent() for that).
Returns: bool — True if the path has a '..' component
canonical¶
| Spice | |
|---|---|
Resolves the path to an absolute, symlink-free, '.'/'..' -free canonical form.
Returns: FilePath — The canonical path, or an empty FilePath if resolution failed (e.g. the path does not exist)
equivalent¶
| Spice | |
|---|---|
Checks whether two paths refer to the same file after resolving symlinks and '.'/'..' components.
Parameters
| Name | Type | Description |
|---|---|---|
other |
const FilePath& |
Other path to compare against |
Returns: bool — True if both paths resolve to the same canonical path (and resolution succeeded for both)
lexicallyNormal¶
| Spice | |
|---|---|
Lexically normalizes the path, like std::filesystem::path::lexically_normal: the separators are made generic ('/'), '.' and empty components are dropped and '..' components are resolved against the preceding component. '..' components at the start of a relative path are kept and '..' components directly after the root are dropped. The file system is not accessed, so symlinks are not resolved.
Returns: FilePath — The normalized path. '.' for an empty result of a relative path
lexicallyRelative¶
| Spice | |
|---|---|
Computes the path relative to the given base path, purely lexically, like std::filesystem::path::lexically_relative. Both paths are normalized first. The file system is not accessed, so symlinks are not resolved.
Parameters
| Name | Type | Description |
|---|---|---|
base |
const FilePath& |
Base path |
Returns: FilePath — The relative path, '.' if both paths are equal, or an empty path if the roots of both paths differ (e.g. one is absolute and the other is not, or they are on different drives)
relative¶
| Spice | |
|---|---|
Computes the path relative to the current working directory, like std::filesystem::relative. Both the path and the working directory are made absolute and canonical, if they exist. Otherwise, they are only normalized lexically.
Returns: FilePath — The relative path, or an empty path if it could not be determined (e.g. the path is on another drive)
Functions¶
testFilePathPathSafetySmoke¶
| Spice | |
|---|---|
Returns: bool
Operators¶
operator==¶
| Spice | |
|---|---|
Check if two file paths are equal
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const FilePath& |
|
rhs |
const FilePath& |
Returns: bool — Equal or not equal
operator!=¶
| Spice | |
|---|---|
Check if two file paths are not equal
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const FilePath& |
|
rhs |
const FilePath& |
Returns: bool — Not equal or equal
operator/=¶
| Spice | |
|---|---|
Append a path component to the path, inserting a separator if needed
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
FilePath& |
|
rhs |
string |
Path component to append |
operator/=¶
| Spice | |
|---|---|
Append a path component to the path, inserting a separator if needed
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
FilePath& |
|
rhs |
const String& |
Path component to append |
operator/=¶
| Spice | |
|---|---|
Append a path component to the path, inserting a separator if needed
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
FilePath& |
|
rhs |
const FilePath& |
Path component to append |
operator/¶
| Spice | |
|---|---|
Join a path and a path component into a new file path, inserting a separator if needed
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const FilePath& |
|
rhs |
string |
Returns: FilePath — New joined file path
operator/¶
| Spice | |
|---|---|
Join a path and a path component into a new file path, inserting a separator if needed
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const FilePath& |
|
rhs |
const String& |
Returns: FilePath — New joined file path
operator/¶
| Spice | |
|---|---|
Join two file paths into a new file path, inserting a separator if needed
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const FilePath& |
|
rhs |
const FilePath& |
Returns: FilePath — New joined file path