dogma:fs
import { read_file, write_file } from "dogma:fs"
The host must grant the dogma:fs capability for these functions to be available. See the Embedding Guide.
Reading files🔗
| Function | Signature | Description |
read_file | (path: String) -> String | Read file as UTF-8 string |
read_file_bytes | (path: String) -> [i32] | Read file as raw byte array |
Writing files🔗
| Function | Signature | Description |
write_file | (path: String, content: String) | Write string to file (creates or overwrites) |
append_file | (path: String, content: String) | Append string to file |
Directory operations🔗
| Function | Signature | Description |
read_dir | (path: String) -> [String] | List directory contents (names only) |
mkdir | (path: String) | Create directory and all parents |
remove | (path: String) | Delete file or empty directory |
Path utilities🔗
| Function | Signature | Description |
exists | (path: String) -> bool | Return true if path exists |
is_file | (path: String) -> bool | Return true if path is a regular file |
is_dir | (path: String) -> bool | Return true if path is a directory |
copy | (src: String, dst: String) | Copy file from src to dst |
rename | (src: String, dst: String) | Move/rename file or directory |
import { read_file, write_file, exists } from "dogma:fs"
import { println } from "dogma:core"
fn main() {
if exists("output.txt") {
let content = read_file("output.txt")
println(f"Existing content: {content}")
}
write_file("output.txt", "Hello from Dogma!\n")
}