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.
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 absoluteReturns the absolute form of this path, resolved against the current working directory if it is relative.
Implementation
Path get absolute => Path(p.absolute(_repr));extension no setter
String get extensionThe file extension of this path, including the leading dot (e.g. '.dart'). Returns an empty string if there is no extension.
Implementation
String get extension => p.extension(_repr);fileName no setter
Path get fileNameThe final component of this path (the file or directory name).
Implementation
Path get fileName => Path(p.basename(_repr));isAbsolute no setter
bool get isAbsoluteWhether this path is absolute.
Implementation
bool get isAbsolute => p.isAbsolute(_repr);names no setter
Splits this path into its individual components.
For example, Path('/home/user/file.txt').names yields ['/', 'home', 'user', 'file.txt'].
Implementation
IList<Path> get names => p.split(_repr).map((p) => Path(p)).toIList();normalize no setter
Path get normalizeReturns a normalized copy of this path, resolving . and .. segments and removing redundant separators.
Implementation
Path get normalize => Path(p.normalize(_repr));parent no setter
The parent directory of this path, or None if this path is already a root (e.g. '/' or 'C:\').
Implementation
Option<Path> get parent => Some(Path(p.dirname(_repr))).filter((p) => p._repr != _repr);Methods
relativize()
Computes the relative path from this directory to path.
Path('/home/user').relativize(Path('/home/user/docs/readme.md'))
// => docs/readme.mdImplementation
Path relativize(Path path) => Path(p.relative(path._repr, from: _repr));Operators
operator +()
Joins this path with path, returning a normalized result.
Equivalent to p.join followed by normalize.
Implementation
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:
Path('/home') / 'user' / 'docs' // /home/user/docsImplementation
Path operator /(String name) => Path(p.join(_repr, name)).normalize;Static Properties
current no setter
Path get currentThe current working directory of the process.
Implementation
static Path get current => Path(p.current);