Bnlang File Stats
File stats are metadata about a file or directory — its size, whether it's a regular file or directory, and when it was last modified.
The built-in io module exposes this through io.stat, plus a handful of one-question helpers.
io.stat — Full Metadata Map
io.stat(path) returns a map with these fields:
bytes— file size in bytes (number).mtime— last modification time as a Unix timestamp in seconds (number).is_dir—trueif the path is a directory.is_file—trueif the path is a regular file.
import "io" as io;
var s = io.stat("notes.txt");
print("size:", s.bytes, "bytes");
print("is file?", s.is_file);
print("is dir?", s.is_dir);
print("mtime:", s.mtime, "seconds since epoch");
Quick Boolean Checks
For yes/no questions, skip the full stat and use the dedicated helpers — they're more readable and avoid loading metadata you don't need.
import "io" as io;
if (io.exists("notes.txt")) {
print("the file is there");
}
if (io.is_file("notes.txt")) {
print("and it's a regular file");
}
if (io.is_dir("data")) {
print("data/ is a directory");
}
Best Practices
- Use
io.existsfirst when you're not sure a path will be valid —io.statthrows on missing files. - Sizes are reported in bytes. Convert in your own code if you want KB / MB.
mtimeis in seconds; multiply by 1000 if you need milliseconds for thetimemodule.