Pyro

A dynamically-typed, garbage-collected scripting language.

Version 0.19.2

std::fs


This module contains file system 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::fs::{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::fs::{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::fs::{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::fs::{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.