/fs
Filesystem operations: reading, writing, copying, moving, recursive tree listing, glob matching, and path canonicalization.
Functions & symbols#
canonicalize#
Resolves relative paths, symlinks, and `..` segments to an absolute normalized path.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Relative or symlinked path |
Any(let abs-path (fs/canonicalize "../config.json"))close#
Flushes any buffered writes and closes an open file handle.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open file handle |
Any(fs/close f)copy#
Copies source file to target destination, returning bytes copied.
| Parameter | Type | Optional | Description |
|---|---|---|---|
source | String | required | Source file |
target | String | required | Target file |
Any(fs/copy "a.txt" "b.txt")copy-directory#
Recursively copies a directory tree from `src` to `dest`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
src | String | required | Source directory |
dest | String | required | Destination directory |
Any(fs/copy-directory "./assets" "./dist/assets")create#
Creates a new file (or truncates existing) opened for writing.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | File path to create or truncate |
Any(let f (fs/create "./out.txt"))create-directory#
Recursively creates the directory at path (equivalent to mkdir -p).
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Directory path to create |
Any(fs/create-directory "./build/dist")create-temp-dir#
Creates a unique temporary directory on disk and returns its absolute path.
| Parameter | Type | Optional | Description |
|---|---|---|---|
prefix-or-options | (Or String Map) | required | Optional prefix String or {:prefix "..." :suffix "..." :dir "..."} Map |
Any(let dir (try (fs/create-temp-dir "build-")))(let dir (try (fs/create-temp-dir {:prefix "test-" :suffix "-work"})))create-temp-file#
Creates a unique temporary file on disk (closing the handle immediately) and returns its absolute path.
| Parameter | Type | Optional | Description |
|---|---|---|---|
prefix-or-options | (Or String Map) | required | Optional prefix String or {:prefix "..." :suffix "..." :dir "..."} Map |
Any(let path (try (fs/create-temp-file "upload-")))(let path (try (fs/create-temp-file {:prefix "doc-" :suffix ".json"})))exists?#
Returns true if the file or directory at path exists, otherwise false.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | The file or directory path to check |
Any(if (fs/exists? "./data.json") (say "found") (else (say "missing")))flush#
Flushes buffered writes in `file` to the operating system.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open writable file handle |
Any(fs/flush f)get-current-dir#
Returns the absolute path of the current working directory.
Anyis-directory?#
Returns true if path exists and points to a directory, or false if the path does not exist.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Path to test |
Anyis-file?#
Returns true if path exists and points to a regular file, or false if the path does not exist.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Path to test |
Anyis-symlink?#
Returns true if path is a symbolic link (including dangling symlinks), or false if the path does not exist.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Path to test |
Any(fs/is-symlink? "./latest")list#
Lists file and folder paths in the directory. Accepts optional {:include-dirs true}.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Directory path to list |
Any(let files (fs/list "."))list-as-tree#
Recursively walks directory and returns hierarchy tree.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Root directory path |
Anyopen#
Opens a file handle with explicit mode flags (`:read`, `:write`, `:append`, `:create`, etc.).
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | File path |
options | Map | required | Mode flags {:read :write :append :truncate :create :create-new :buffered} |
Any(let f (fs/open "app.log" {:append true :create true}))read#
Reads raw bytes from `file` into `buf` and returns byte count read.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open readable file handle |
buf | Slab | required | Mutable Slab buffer to fill |
Any(fs/read f slab)read-all#
Reads all remaining bytes from `file` until EOF into a byte `Slab`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open readable file handle |
Any(fs/read-all f)read-byte#
Reads a single byte (`U8`) from `file`, or `()` at EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open readable file handle |
Any(fs/read-byte f)read-char#
Reads a single UTF-8 `Char` from `file`, or `()` at EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open text file handle |
Any(fs/read-char f)read-line#
Reads the next UTF-8 line (stripping trailing newline) from `file`, or `()` at EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open text file handle |
Any(fs/read-line f)read-link#
Reads the immediate target path of a symbolic link without resolving intermediate links.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Symbolic link path to read |
Any(let target (try (fs/read-link "./current")))read-slab-from-file#
Reads raw bytes of a file into a binary Slab buffer.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Path to binary file |
Anyread-string#
Reads all remaining UTF-8 text from `file` until EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open text file handle |
Any(fs/read-string f)read-string-from-file#
Reads the complete UTF-8 contents of a file at path into a String. Returns an Error if the file cannot be read.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Path of the file to read |
Any(let content (fs/read-string-from-file "config.json"))remove-directory#
Recursively removes the directory at path and all its contents by default. Pass {:recursive false} to fail on non-empty directories.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Directory path to remove |
options | (Or Map) | required | Optional {:recursive false} to require an empty directory |
Any(fs/remove-directory "./tmp")(fs/remove-directory "./empty-dir" {:recursive false})remove-file#
Deletes a regular file or symlink at `path`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | File path to unlink |
Any(fs/remove-file "./tmp.txt")rename#
Renames or moves a file or directory from one path to another.
| Parameter | Type | Optional | Description |
|---|---|---|---|
from | String | required | Current path |
to | String | required | New path |
Any(fs/rename "old.txt" "new.txt")stat#
Returns a metadata Map with :size (Int), :modified-at (Instant), :created-at (Instant or ()), :accessed-at (Instant or ()), :is-file (Bool), :is-dir (Bool), :is-symlink (Bool), :readonly (Bool), and :mode (Int or ()).
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | File, directory, or symlink path to inspect |
options | (Or Map) | required | Optional {:follow-symlinks false} to inspect the link itself without following |
Any(let info (try (fs/stat "./config.json")))(let link-info (try (fs/stat "./latest" {:follow-symlinks false})))symlink#
Creates a symbolic link at link-path pointing to target. Returns true on success or an :io Error.
| Parameter | Type | Optional | Description |
|---|---|---|---|
target | String | required | Target path that the symbolic link points to |
link-path | String | required | Path where the symbolic link will be created |
Any(try (fs/symlink "./releases/v1" "./current"))write#
Writes bytes or text to `file` and returns bytes written.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open writable file handle |
data | String | Slab | required | Text or binary bytes to write |
Any(fs/write f "line\n")write-byte#
Writes a single byte to `file`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open writable file handle |
byte | U8 | Int | required | Byte to write |
Any(fs/write-byte f 10u8)write-line#
Writes `line` followed by a newline to `file`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open writable file handle |
line | String | required | Line string to write |
Any(fs/write-line f "entry")write-slab-to-file#
Writes binary Slab buffer to file at path. Returns number of bytes written.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Destination path |
slab | Slab | required | Binary bytes to write |
Anywrite-string#
Writes `text` to `file` without appending a newline.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open writable file handle |
text | String | required | UTF-8 string to write |
Any(fs/write-string f "chunk")write-string-to-file#
Writes content to path, automatically creating parent directories if necessary. Returns the number of bytes written.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path | String | required | Destination file path |
content | String | required | Text content to write |
Any(fs/write-string-to-file "./output/log.txt" "Task completed.")writeln#
Writes `text` followed by a newline to `file`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
file | File | required | Open writable file handle |
text | String | required | UTF-8 string to write |
Any(fs/writeln f "ok")