Skip to content

Dir

Spice
import "std/io/dir";

Functions

mkDir

Spice
public f<int> mkDir(string path, int mode)

Creates an empty directory at the specified path, with the specified mode. Creates at max one directory. If the second last path element does not exist, the operation fails

There are predefined constants for the mode available:
MODE_ALL_RWX, MODE_ALL_RW, MODE_ALL_R,
MODE_OWNER_RWX, MODE_OWNER_R, MODE_OWNER_W, MODE_OWNER_X,
MODE_GROUP_RWX, MODE_GROUP_R, MODE_GROUP_W, MODE_GROUP_X,
MODE_OTHER_RWX, MODE_OTHER_R, MODE_OTHER_W, MODE_OTHER_X

Parameters

Name Type Description
path string
mode int

Returns: int — Result code of the create operation: 0 = successful, -1 = failed

rmDir

Spice
public f<int> rmDir(string path)

Deletes an empty directory at the specified path.

Parameters

Name Type Description
path string

Returns: int — Result code of the delete operation: 0 = successful, -1 = failed

renameDir

Spice
public f<int> renameDir(string oldPath, string newPath)

Renames a directory.

Parameters

Name Type Description
oldPath string
newPath string

Returns: int — Result code of the rename operation: 0 = successful, -1 = failed

dirExists

Spice
public f<bool> dirExists(string path)

Checks if a directory is existing.

Parameters

Name Type Description
path string

Returns: bool — Existing or not

mkDirs

Spice
public f<int> mkDirs(string path, int mode)

Creates an empty directory at the specified path, with the specified mode. Unlike mkDir, mkDirs can also create nested path structures: any missing parent directories are created along the way, in order. Directories that already exist anywhere along the path (including the target itself) are left as is.

There are predefined constants for the mode available:
MODE_ALL_RWX, MODE_ALL_RW, MODE_ALL_R,
MODE_OWNER_RWX, MODE_OWNER_R, MODE_OWNER_W, MODE_OWNER_X,
MODE_GROUP_RWX, MODE_GROUP_R, MODE_GROUP_W, MODE_GROUP_X,
MODE_OTHER_RWX, MODE_OTHER_R, MODE_OTHER_W, MODE_OTHER_X

Parameters

Name Type Description
path string
mode int

Returns: int — Result code of the create operation: 0 = successful, -1 = failed

listDir

Spice
public f<Result<Vector<String>>> listDir(string path)

Lists the names of all files and subdirectories directly inside the given directory. The entries '.' and '..' are left out. The names are listed in the order, in which the operating system reports them.

Parameters

Name Type Description
path string Path to the directory

Returns: Result<Vector<String>> — Names of the entries, or an error if the directory could not be opened

listDirRecursive

Spice
public f<Result<Vector<String>>> listDirRecursive(string path)

Lists all files and subdirectories inside the given directory and, recursively, inside its subdirectories. Each entry is reported as a path relative to the given directory, with '/' as separator. A directory is listed before its contents. Symbolic links to directories are listed, but not descended into. Subdirectories, that cannot be opened (e.g. due to missing permissions) are listed, but their contents are left out.

Parameters

Name Type Description
path string Path to the directory

Returns: Result<Vector<String>> — Relative paths of the entries, or an error if the directory could not be opened