Path data type and helper functions
path
- A path or fragment of a filesystem pathbasename
- Get the file name portion of a pathconnect
- Connects to path segmentsconnect_many
- Connects a vector of path segments into a single path.dirname
- Get the directory portion of a pathnormalize
- Collapses redundant path separators.path_is_absolute
- Indicates whether a path is absolute.path_sep
- Get the default path separator for the host platformsplit
- Split a path into its individual componentssplitext
- Split a path into the part before the extension and the extensionpath::consts
path
type path = str
A path or fragment of a filesystem path
basename
fn basename(pp: path) -> path
Get the file name portion of a path
Returns the portion of the path after the final path separator. The basename of "/usr/share" will be "share". If there are no path separators in the path then the returned path is identical to the provided path. If an empty path is provided or the path ends with a path separator then an empty path is returned.
connect
fn connect(pre: path, post: path) -> path
Connects to path segments
Given paths pre
and post, removes any trailing path separator on
preand any leading path separator on
post`, and returns the concatenation of the two with a single path separator between them.
connect_many
fn connect_many(paths: ~[path]) -> path
Connects a vector of path segments into a single path.
Inserts path separators as needed.
dirname
fn dirname(pp: path) -> path
Get the directory portion of a path
Returns all of the path up to, but excluding, the final path separator. The dirname of "/usr/share" will be "/usr", but the dirname of "/usr/share/" is "/usr/share".
If the path is not prefixed with a directory, then "." is returned.
normalize
fn normalize(p: path) -> path
Collapses redundant path separators.
Does not follow symbolic links.
path_is_absolute
fn path_is_absolute(p: path) -> bool
Indicates whether a path is absolute.
A path is considered absolute if it begins at the filesystem root ("/") or, on Windows, begins with a drive letter.
path_sep
fn path_sep() -> str
Get the default path separator for the host platform
split
fn split(p: path) -> ~[path]
Split a path into its individual components
Splits a given path by path separators and returns a vector containing each piece of the path. On Windows, if the path is absolute then the first element of the returned vector will be the drive letter followed by a colon.
splitext
fn splitext(p: path) -> (str, str)
Split a path into the part before the extension and the extension
Split a path into a pair of strings with the first element being the filename without the extension and the second being either empty or the file extension including the period. Leading periods in the basename are ignored. If the path includes directory components then they are included in the filename part of the result pair.