Finch/tests/new/std_fs.fch
Nexoniarz f2d6480749 const, if as a value, """ text over several lines, min/max/abs/clamp, import a/b and import x as y, the fs module
- const NAME = value (numbers, text, other constants; typed: const f32 G = 9.8), also module.NAME
- x := if c { a } else { b }
- """ ... """: the closing quotes' indentation goes from every line
- min, max, abs, clamp for any numbers, unless your own function has the name
- import ui/button (a module in a folder), import path as p
- fs: read_bytes, write_bytes, exists, is_dir, mkdir (with parents), list, remove_dir, data_dir(app)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GzNP6r8dg6WDxUVZy8wjL
2026-10-29 09:37:41 +01:00

23 lines
845 B
Text

// the fs module: bytes with NUL in them, folders, listing
import fs
fn main() -> ! {
root := "fs_test_dir"
try fs.mkdir(root + "/a/b")
print(fs.exists(root), fs.is_dir(root + "/a/b"), fs.is_dir("nope"))
data := [u8(0), u8(255), u8(13), u8(10), u8(65)]
try fs.write_bytes(root + "/a/blob.bin", data)
back := try fs.read_bytes(root + "/a/blob.bin")
print(back.len, back[0], back[1], back[4], str(back) == str(data))
write_file(root + "/z.txt", "z")
print(try fs.list(root))
print(try fs.list(root + "/a"))
print(fs.list("no_such_dir") or ["(none)"])
delete_file(root + "/a/blob.bin")
delete_file(root + "/z.txt")
try fs.remove_dir(root + "/a/b")
try fs.remove_dir(root + "/a")
try fs.remove_dir(root)
print(fs.exists(root))
fs.remove_dir(root) or { print("gone:", err) }
}