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(using(io : IO)) -> unit)({
  given(exn) : Exception = {
    throw : (fn(forall(T : Type), error: AnyError) -> T)(
      { println(error.to_string()); exit(i32(1)); }
    )
  };

  io.await(create_dir(Path.new(`/tmp/yo_test`)));
  entries := io.await(read_dir(Path.new(`/tmp/yo_test`)));
  io.await(remove_dir(Path.new(`/tmp/yo_test`)));
});

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, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Create a directory at the given path.

Parameters

NameTypeNotes
pathPath

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

create_dir_str function
fn(path : str, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Create a directory (str path variant).

Parameters

NameTypeNotes
pathstr

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

create_dir_all function
fn(path : Path, using(io : IO)) -> Impl(Future(unit, IO, Exception))

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

Parameters

NameTypeNotes
pathPath

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

fn(path : str, using(io : IO)) -> Impl(Future(unit, IO, Exception))

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

Parameters

NameTypeNotes
pathstr

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

remove_dir function
fn(path : Path, using(io : IO)) -> Impl(Future(unit, IO, Exception))

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

Parameters

NameTypeNotes
pathPath

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

remove_dir_str function
fn(path : str, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Parameters

NameTypeNotes
pathstr

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

remove_file function
fn(path : Path, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Remove a file at the given path.

Parameters

NameTypeNotes
pathPath

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

remove_file_str function
fn(path : str, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Parameters

NameTypeNotes
pathstr

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

rename function
fn(from : Path, to : Path, using(io : IO)) -> Impl(Future(unit, IO, Exception))

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

Parameters

NameTypeNotes
fromPath
toPath

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

rename_str function
fn(from : str, to : str, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Parameters

NameTypeNotes
fromstr
tostr

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(unit, IO, Exception))

read_dir function
fn(path : Path, using(io : IO)) -> Impl(Future(ArrayList(DirEntry), IO, Exception))

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

Parameters

NameTypeNotes
pathPath

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(ArrayList(DirEntry), IO, Exception))

read_dir_str function
fn(path : str, using(io : IO)) -> Impl(Future(ArrayList(DirEntry), IO, Exception))

Parameters

NameTypeNotes
pathstr

Effects

NameTypeNotes
ioIOcomptime, implicit

Returns: Impl(Future(ArrayList(DirEntry), IO, Exception))