Skip to content

Path

extension type Path(String)

A cross-platform filesystem path.

Path wraps a String and delegates to the path package for platform-aware joining, normalization, and decomposition. All operations that combine or resolve paths produce normalized results.

dart
final config = Path('/etc') / 'app' / 'config.yaml';
print(config);           // /etc/app/config.yaml
print(config.fileName);  // config.yaml
print(config.extension); // .yaml
print(config.parent);    // Some(/etc/app)

Constructors

Path()

Path(String _repr)

Properties

absolute no setter

Path get absolute

Returns the absolute form of this path, resolved against the current working directory if it is relative.

Implementation
dart
Path get absolute => Path(p.absolute(_repr));

extension no setter

String get extension

The file extension of this path, including the leading dot (e.g. '.dart'). Returns an empty string if there is no extension.

Implementation
dart
String get extension => p.extension(_repr);

fileName no setter

Path get fileName

The final component of this path (the file or directory name).

Implementation
dart
Path get fileName => Path(p.basename(_repr));

isAbsolute no setter

bool get isAbsolute

Whether this path is absolute.

Implementation
dart
bool get isAbsolute => p.isAbsolute(_repr);

names no setter

IList<Path> get names

Splits this path into its individual components.

For example, Path('/home/user/file.txt').names yields ['/', 'home', 'user', 'file.txt'].

Implementation
dart
IList<Path> get names => p.split(_repr).map((p) => Path(p)).toIList();

normalize no setter

Path get normalize

Returns a normalized copy of this path, resolving . and .. segments and removing redundant separators.

Implementation
dart
Path get normalize => Path(p.normalize(_repr));

parent no setter

Option<Path> get parent

The parent directory of this path, or None if this path is already a root (e.g. '/' or 'C:\').

Implementation
dart
Option<Path> get parent => Some(Path(p.dirname(_repr))).filter((p) => p._repr != _repr);

Methods

relativize()

Path relativize(Path path)

Computes the relative path from this directory to path.

dart
Path('/home/user').relativize(Path('/home/user/docs/readme.md'))
// => docs/readme.md
Implementation
dart
Path relativize(Path path) => Path(p.relative(path._repr, from: _repr));

Operators

operator +()

Path operator +(Path path)

Joins this path with path, returning a normalized result.

Equivalent to p.join followed by normalize.

Implementation
dart
Path operator +(Path path) => Path(p.join(_repr, path._repr)).normalize;

operator /()

Path operator /(String name)

Appends a single path segment name to this path, returning a normalized result.

This is a convenient shorthand for joining with a literal string:

dart
Path('/home') / 'user' / 'docs'  // /home/user/docs
Implementation
dart
Path operator &#47;(String name) => Path(p.join(_repr, name)).normalize;

Static Properties

current no setter

Path get current

The current working directory of the process.

Implementation
dart
static Path get current => Path(p.current);