Skip to main content

Path

Represents a filesystem path.

class Path

Constructor​

constructor(_ path: String)
_ path: String

The string representation of the path.

Properties​

parent​

parent: Path { get }

The parent path component. Returns an empty path if the path has no parent (e.g. a single filename with no directory separator, or an empty path).


root_name​

root_name: Path { get }

The root name component. On Windows, this is the drive identifier (e.g. C:). On POSIX systems it is always empty. Returns an empty path if the path has no root name.


root_directory​

root_directory: Path { get }

The root directory separator (e.g. / on POSIX systems). Returns an empty path if the path has no root directory.


root​

root: Path { get }

The root path (root name combined with root directory). Returns an empty path if the path has no root.


filename​

filename: Path { get }

The filename component, i.e. the last path component. Returns an empty path if the path contains no filename.


stem​

stem: Path { get }

The filename without its extension. Returns an empty path if the path has no stem.


extension​

extension: Path { get }

The file extension, including the leading dot (e.g. .wav). Returns an empty path if the path has no extension.


has_parent​

has_parent: Bool { get }

Whether the path has a parent path.


has_root_name​

has_root_name: Bool { get }

Whether the path has a root name.


has_root​

has_root: Bool { get }

Whether the path has a root directory separator.


has_filename​

has_filename: Bool { get }

Whether the path has a filename component.


has_stem​

has_stem: Bool { get }

Whether the path has a stem.


has_extension​

has_extension: Bool { get }

Whether the path has an extension.


is_absolute​

is_absolute: Bool { get }

Whether the path is absolute.


is_relative​

is_relative: Bool { get }

Whether the path is relative.


is_empty​

is_empty: Bool { get }

Whether the path is empty.

Methods​

appending​

Returns a new path with additional components appended. Available as several overloads:

Single Component​

appending(_ path: String) -> (Path)

Returns a new path with the given path string appended as a new path component.

Another Path​

appending(_ other: Path) -> (Path)

Returns a new path with other's components appended.

Multiple Segments​

appending(_ segments: [Path]) -> (Path)

Returns a new path with all segments from the given array appended in order as new path components.


removing_filename​

removing_filename() -> (Path)

Returns a new path with the filename component removed.


replacing_filename​

replacing_filename(_ filename: Path) -> (Path)

Returns a new path with the filename component replaced by filename.


replacing_extension​

replacing_extension(_ extension: Path) -> (Path)

Returns a new path with the extension replaced by extension.


relative​

relative(to base: Path) -> (Path)

Returns this path expressed relative to base.


equal​

equal(to other: Path) -> (Bool)

Returns whether the path compares equal to other, ignoring differences between path separator characters.


to_string​

to_string() -> (String)

Returns the UTF-8 string representation of the path.


to_uri​

to_uri() -> (URI?)

Returns the path as an optional file URI, of format file://<path>. In case of an empty path, the returned value is nil.