Module fs/dir

fs/dir

Async directory operations — create, remove, read, link, rename.

Wraps low-level std/sys/dir with typed APIs using the Exception effect.

Example

{ create_dir, remove_dir, read_dir } :: import "std/fs/dir";
{ Path } :: import "std/path";

main :: (fn(io : Io, exn : Exception) -> unit)({
  io.await(create_dir(Path.new(`/tmp/yo_test`), io), { io, exn });
  entries := io.await(read_dir(Path.new(`/tmp/yo_test`), io), { io, exn });
  io.await(remove_dir(Path.new(`/tmp/yo_test`), io), { io, exn });
});

Types

FileType enum
FileType

The type of a file system entry.

Variants

VariantFieldsDescription
File

A regular file.

Directory

A directory.

Symlink

A symbolic link.

Other

An unknown or unsupported file type.

DirEntry struct
DirEntry

A directory entry containing the entry name, file type, and inode number.

Fields

NameTypeDescription
nameString
file_typeFileType
inou64

Functions

create_dir function
fn(path : Path, io : Io) -> Impl(Future(unit, IoExn))

Create a directory at the given path.

Parameters

NameTypeNotes
pathPath
ioIo

Returns: Impl(Future(unit, IoExn))

create_dir_str function
fn(path : str, io : Io) -> Impl(Future(unit, IoExn))

Create a directory (str path variant).

Parameters

NameTypeNotes
pathstr
ioIo

Returns: Impl(Future(unit, IoExn))

create_dir_all function
fn(path : Path, io : Io) -> Impl(Future(unit, IoExn))

Create a directory and all missing parent directories. Does not error if the directory already exists.

Parameters

NameTypeNotes
pathPath
ioIo

Returns: Impl(Future(unit, IoExn))

fn(path : str, io : Io) -> Impl(Future(unit, IoExn))

Create a directory and all missing parents (str path variant).

Parameters

NameTypeNotes
pathstr
ioIo

Returns: Impl(Future(unit, IoExn))

remove_dir function
fn(path : Path, io : Io) -> Impl(Future(unit, IoExn))

Remove an empty directory. Throws if the directory is not empty.

Parameters

NameTypeNotes
pathPath
ioIo

Returns: Impl(Future(unit, IoExn))

remove_dir_str function
fn(path : str, io : Io) -> Impl(Future(unit, IoExn))

Parameters

NameTypeNotes
pathstr
ioIo

Returns: Impl(Future(unit, IoExn))

remove_file function
fn(path : Path, io : Io) -> Impl(Future(unit, IoExn))

Remove a file at the given path.

Parameters

NameTypeNotes
pathPath
ioIo

Returns: Impl(Future(unit, IoExn))

remove_file_str function
fn(path : str, io : Io) -> Impl(Future(unit, IoExn))

Parameters

NameTypeNotes
pathstr
ioIo

Returns: Impl(Future(unit, IoExn))

rename function
fn(from : Path, to : Path, io : Io) -> Impl(Future(unit, IoExn))

Rename or move a file or directory from from to to.

Parameters

NameTypeNotes
fromPath
toPath
ioIo

Returns: Impl(Future(unit, IoExn))

rename_str function
fn(from : str, to : str, io : Io) -> Impl(Future(unit, IoExn))

Parameters

NameTypeNotes
fromstr
tostr
ioIo

Returns: Impl(Future(unit, IoExn))

read_dir function
fn(path : Path, io : Io) -> Impl(Future(ArrayList(DirEntry), IoExn))

Read all entries from a directory, returning an ArrayList(DirEntry). Skips the . and .. entries.

Parameters

NameTypeNotes
pathPath
ioIo

Returns: Impl(Future(ArrayList(DirEntry), IoExn))

read_dir_str function
fn(path : str, io : Io) -> Impl(Future(ArrayList(DirEntry), IoExn))

Parameters

NameTypeNotes
pathstr
ioIo

Returns: Impl(Future(ArrayList(DirEntry), IoExn))