Pyro

A scripting language for people who enjoy the simpler things in life.

Version 0.9.35

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 calling normpath(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 true if path exists. If path is a symlink, returns true if the target of the link exists.

is_dir(path: str) -> bool

Returns true if path exists and is a directory. If path is a symlink, returns true if the target of the link exists and is a directory.

is_file(path: str) -> bool

Returns true if path exists and is a regular file. If path is a symlink, returns true if the target of the link exists and is a regular file.

is_symlink(path: str) -> bool

Returns true if path exists 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 path is not a directory.

normpath(path: str) -> str

Normalizes the filepath path by 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 path must exist. Equivalent to POSIX realpath().

Panics if the path cannot be resolved.

remove(path: str)

Deletes the file, symlink, or directory at path.

  • If path is a symlink, the link itself will be deleted, not its target.
  • If path is a directory, the directory and all its content will be deleted.