std::path
This module contains filepath utilities.
Functions
-
abspath(path: str) -> str -
Returns the normalized, absolute version of the filepath
path. This is equivalent to callingnormpath(join(getcwd(), path)). -
basename(path: str) -> str -
Returns the base name of the filepath
path.Examples:
import std::path::{basename}; assert basename("") == ""; assert basename("/") == ""; assert basename("/foo.txt") == "foo.txt"; assert basename("foo.txt/") == ""; assert basename("foo.txt") == "foo.txt"; assert basename("foo/bar.txt") == "bar.txt"; assert basename("/foo/bar.txt") == "bar.txt";
-
chdir(path: str) -
Changes the current working directory to
path. -
getcwd() -> str -
Returns the path of the current working directory.
-
dirname(path: str) -> str -
Returns the directory name of the filepath
path.Examples:
import std::path::{dirname}; assert dirname("") == ""; assert dirname("/") == "/"; assert dirname("/foo.txt") == "/"; assert dirname("foo.txt/") == "foo.txt"; assert dirname("foo.txt") == ""; assert dirname("foo/bar.txt") == "foo"; assert dirname("/foo/bar.txt") == "/foo";
-
exists(path: str) -> bool -
Returns
trueifpathexists. Ifpathis a symlink, returnstrueif the target of the link exists. -
is_dir(path: str) -> bool -
Returns
trueifpathexists and is a directory. Ifpathis a symlink, returnstrueif the target of the link exists and is a directory. -
is_file(path: str) -> bool -
Returns
trueifpathexists and is a regular file. Ifpathis a symlink, returnstrueif the target of the link exists and is a regular file. -
is_symlink(path: str) -> bool -
Returns
trueifpathexists and is a symlink. (This checks if the symlink itself exists, not its target.) -
join(path: str, *paths: str) -> str -
Joins one or more path segments, adding
/separators as required.If a segment is an absolute path — i.e. begins with a
/— all previous segments are ignored and joining continues from the absolute path segment.Examples:
import std::path::{join}; assert join("") == ""; assert join("foo") == "foo"; assert join("foo", "bar") == "foo/bar"; assert join("/foo/", "bar") == "/foo/bar"; assert join("/foo/", "/bar") == "/bar";
-
listdir(path: str) -> vec[str] -
Returns a vector containing the names of the entries in the directory specified by
path. Skips"."and"..".Panics if
pathis not a directory. -
normpath(path: str) -> str -
Normalizes the filepath
pathby collapsing redundant//and.separators and up-leveling..references.Examples:
import std::path::{normpath}; assert normpath("foo//bar") == "foo/bar"; assert normpath("foo/./bar") == "foo/bar"; assert normpath("foo/../bar") == "bar";
For paths beginning with exactly two slashes,
//, the leading two slashes are preserved in accordance with POSIX pathname resolution. -
realpath(path: str) -> str -
Returns the canonicalized absolute path, resolving all symbolic links. All the components of
pathmust exist. Equivalent to POSIXrealpath().Panics if the path cannot be resolved.
-
remove(path: str) -
Deletes the file, symlink, or directory at
path.-
If
pathis a symlink, the link itself will be deleted, not its target. -
If
pathis a directory, the directory and all its content will be deleted.
-
If