Module 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 });
});
Every operation here is async: it submits to the single-threaded event
loop and must be awaited, and it reports failure by throwing IoExn
carrying the OS errno as an IoError (D1), never by returning a
Result. Each Path-taking function has a _str twin that differs only
in accepting a borrowed str literal.
Stability
unstable — read_dir is eager and Rust's is not. It drains the whole
directory into an ArrayList(DirEntry) before the future resolves, so a
caller that wants the first matching entry pays for every entry, and a
directory with a million entries is a million-entry allocation rather
than a cursor. Rust's fs::read_dir is an iterator of
io::Result<DirEntry>, which also lets ONE unreadable entry be reported
without failing the listing. The entry order is whatever the filesystem
returns, deliberately (Rust promises nothing either), and callers that
need determinism sort. Freezing follows a lazy ReadDir cursor beside
the eager form, not a release count.
Types
The type of a file system entry.
Variants
| Variant | Fields | Description |
|---|---|---|
File | A regular file. | |
Directory | A directory. | |
Symlink | A symbolic link. | |
Other | An unknown or unsupported file type. |
A directory entry containing the entry name, file type, inode number, and
the directory it was read from (so path() can rebuild the full path —
Rust's DirEntry::path).
Fields
| Name | Type | Description |
|---|---|---|
name | String | The entry's own name, with no directory part — Rust's
|
file_type | FileType | The |
ino | u64 | Inode number from the directory entry. Filesystem identity, not
content: two names sharing an |
parent | Path | The directory this entry was read from, kept so |
Functions
Create a directory and all missing parent directories. Does not error if the directory already exists.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
path | Path | The full path of this entry: the scanned directory joined with the
entry name. Rust's | |
io | Io |
Returns: Impl(Future(unit, IoExn))
Remove an empty directory. Throws if the directory is not empty.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
path | Path | The full path of this entry: the scanned directory joined with the
entry name. Rust's | |
io | Io |
Returns: Impl(Future(unit, IoExn))
Read all entries from a directory, returning an ArrayList(DirEntry).
Skips the . and .. entries.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
path | Path | The full path of this entry: the scanned directory joined with the
entry name. Rust's | |
io | Io |
Read a symlink's target (std::fs::read_link). Throws for a path that is
not a symlink (EINVAL) — like Rust.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
path | Path | The full path of this entry: the scanned directory joined with the
entry name. Rust's | |
io | Io |
The FileType of the entry at path, WITHOUT following a final symlink
(lstat semantics): a symlink reports .Symlink, never its target's
type. That is the same view readdir's d_type gives, so a walk sees one
consistent answer whatever the filesystem reports, and
WalkOptions.follow_symlinks — not the stat — stays in charge of descent.
Throws when the path cannot be stat'ed.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
path | Path | The full path of this entry: the scanned directory joined with the
entry name. Rust's | |
io | Io |