Skip to content

Path

extension typePath(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

Pathgetabsolute

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

Stringgetextension

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

PathgetfileName

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

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

isAbsolute no setter

boolgetisAbsolute

Whether this path is absolute.

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

names no setter

IList<Path>getnames

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

Pathgetnormalize

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>getparent

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()

Pathrelativize(Pathpath)

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 +()

Pathoperator +(Pathpath)

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 /()

Pathoperator /(Stringname)

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

Pathgetcurrent

The current working directory of the process.

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