Skip to main content

Path Experimental

Represents a filesystem path.

export class Path {
parent: Path { get }
root_name: Path { get }
root_directory: Path { get }
root: Path { get }
filename: Path { get }
stem: Path { get }
extension: Path { get }
has_parent: Bool { get }
has_root_name: Bool { get }
has_root: Bool { get }
has_filename: Bool { get }
has_stem: Bool { get }
has_extension: Bool { get }
is_absolute: Bool { get }
is_relative: Bool { get }
is_empty: Bool { get }

constructor(_ path: String)

appending(_ path: String) -> Path
appending_all(_ segments: [String]) -> Path
appending_path(_ other: Path) -> Path
removing_filename() -> Path
replacing_filename(_ filename: Path) -> Path
replacing_extension(_ extension: Path) -> Path
relative(to base: Path) -> Path
equal(to other: Path) -> Bool
to_string() -> String
to_uri() -> URI?
}
import { Path } from fs

Constructor

_ path: String Required

The string representation of the path.

Properties

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: 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: Path (get)

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

root: Path (get)

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

filename: Path (get)

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

stem: Path (get)

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

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: Bool (get)

Whether the path has a parent path.

has_root_name: Bool (get)

Whether the path has a root name.

has_root: Bool (get)

Whether the path has a root directory separator.

has_filename: Bool (get)

Whether the path has a filename component.

has_stem: Bool (get)

Whether the path has a stem.

has_extension: Bool (get)

Whether the path has an extension.

is_absolute: Bool (get)

Whether the path is absolute.

is_relative: Bool (get)

Whether the path is relative.

is_empty: Bool (get)

Whether the path is empty.

Methods

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

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

appending_all(_ segments: [String]) -> (Path)

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

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

Returns a new path with other appended.

removing_filename() -> (Path)

Returns a new path with the filename component removed.

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

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

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

Returns a new path with the extension replaced by extension.

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

Returns this path expressed relative to base.

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

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

to_string() -> (String)

Returns the UTF-8 string representation of the path.

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.