path library

A comprehensive, cross-platform path manipulation library.

Installing

Use pub to install this package. Add the following to your pubspec.yaml file.

dependencies:
  path: any

Then run pub install.

For more information, see the path package on pub.dartlang.org.

Usage

The path library was designed to be imported with a prefix, though you don't have to if you don't want to:

import 'package:path/path.dart' as path;

The most common way to use the library is through the top-level functions. These manipulate path strings based on your current working directory and the path style (POSIX, Windows, or URLs) of the host platform. For example:

path.join("directory", "file.txt");

This calls the top-level join function to join "directory" and "file.txt" using the current platform's directory separator.

If you want to work with paths for a specific platform regardless of the underlying platform that the program is running on, you can create a Builder and give it an explicit Style:

var builder = new path.Builder(style: Style.windows);
builder.join("directory", "file.txt");

This will join "directory" and "file.txt" using the Windows path separator, even when the program is run on a POSIX machine.

Classes

Builder
An instantiable class for manipulating paths. Unlike the top-level functions, this lets you explicitly select what platform the paths will use.
Style
An enum type describing a "flavor" of path.

Properties

current String
Gets the path to the current working directory. [...]
read-only
posix Builder
A default builder for manipulating POSIX paths.
final
separator String
Gets the path separator for the current platform. This is \ on Windows and / on other platforms (including the browser).
read-only
url Builder
A default builder for manipulating URLs.
final
windows Builder
A default builder for manipulating Windows paths.
final

Functions

absolute(String path) String
Converts path to an absolute path by resolving it relative to the current working directory. If path is already an absolute path, just returns it. [...]
basename(String path) String
Gets the part of path after the last separator. [...]
basenameWithoutExtension(String path) String
Gets the part of path after the last separator, and without any trailing file extension. [...]
dirname(String path) String
Gets the part of path before the last separator. [...]
extension(String path) String
Gets the file extension of path: the portion of basename from the last . to the end (including the . itself). [...]
fromUri(Uri uri) String
Returns the path represented by uri. [...]
isAbsolute(String path) bool
Returns true if path is an absolute path and false if it is a relative path. [...]
isRelative(String path) bool
Returns true if path is a relative path and false if it is absolute. On POSIX systems, absolute paths start with a / (forward slash). On Windows, an absolute path starts with \\, or a drive letter followed by :/ or :\.
isRootRelative(String path) bool
Returns true if path is a root-relative path and false if it's not. [...]
join(String part1, [ String part2, String part3, String part4, String part5, String part6, String part7, String part8 ]) String
Joins the given path parts into a single path using the current platform's separator. Example: [...]
joinAll(Iterable<String> parts) String
Joins the given path parts into a single path using the current platform's separator. Example: [...]
normalize(String path) String
Normalizes path, simplifying it by handling .., and ., and removing redundant path separators whenever possible. [...]
relative(String path, { String from }) String
Attempts to convert path to an equivalent relative path from the current directory. [...]
rootPrefix(String path) String
Returns the root of path, if it's absolute, or the empty string if it's relative. [...]
split(String path) List<String>
Splits path into its components using the current platform's separator. [...]
toUri(String path) Uri
Returns the URI that represents path. [...]
withoutExtension(String path) String
Removes a trailing extension from the last part of path. [...]