Working with Directories in Bnlang

Directories are how a filesystem groups files. The built-in io module gives you everything you need to inspect, create, list, and tear them down — without dragging in a third-party library.


Creating a Directory

io.mkdir(path) creates the directory and all intermediate parents automatically — there's no separate recursive: true flag.

import "io" as io;

io.mkdir("data/users/alice");
print(io.is_dir("data/users/alice"));   // true

Listing Entries

io.list_dir(path) returns a list of entry names (no . or ..).

import "io"   as io;
import "path" as path;

var names = io.list_dir(".");
for (var name of names) {
    var full = path.join([".", name]);
    if (io.is_dir(full)) {
        print("[dir]", name);
    } else {
        print("     ", name);
    }
}

Removing

io.remove(path) deletes a file or a directory. For directories, it removes the contents recursively — be careful.

import "io" as io;

io.remove("data/users/alice");
print(io.exists("data/users/alice"));   // false

Best Practices

  • Use io.is_dir (or io.exists + io.is_dir) before listing or recursing into a path.
  • io.remove is recursive on directories — double-check the path before calling it.
  • Pair io.mkdir with path.join instead of hard-coded separators.