os
Filesystem, process, environment and platform helpers.
Backend: native — stdlib/os.so, built from stdlib/os.cpp over <filesystem> and the host APIs (POSIX or Win32). Import: import("os") → global.os.*
Functions return safe defaults on failure (false, "", -1, an empty list).
Files and directories
| Function | Signature | Notes |
|---|---|---|
getcwd | () -> str | Current working directory |
chdir | (str path) -> bool | Changes the working directory |
listdir | (str path) -> list | Directory entries, in filesystem order |
listdirExt | (str path, str ext) -> list | Entries whose name ends with ext |
walkFiles | (str path) -> str | Recursive file paths as a newline-joined string |
mkdir | (str path) -> bool | Creates one directory; false if it exists |
makedirs | (str path) -> bool | Creates a directory tree (existing is fine) |
rmdir | (str path) -> bool | Removes an empty directory |
remove | (str path) -> bool | Removes a file |
rename | (str src, str dst) -> bool | Renames or moves |
rmTree | (str path) -> bool | Recursively removes a tree |
copyTree | (str src, str dst) -> bool | Recursively copies; fails if dst exists |
exists / isFile / isDir | (str path) -> bool | Path predicates |
Paths and environment
| Function | Signature | Notes |
|---|---|---|
joinPath | (str a, str b) -> str | Joins with the platform separator |
basename / dirname | (str path) -> str | Final / parent component |
absPath | (str path) -> str | Absolute, normalized path |
extname | (str path) -> str | Extension including the dot |
normPath | (str path) -> str | Collapses ., .. and repeated separators |
expandUser | (str path) -> str | Expands a leading ~ or ~user |
sep | () -> str | / on POSIX hosts |
getenv / setenv | (str key[, str value]) | Reads / writes an environment variable |
tempDir | () -> str | $TMPDIR, $TEMP, $TMP, else /tmp (Windows: GetTempPathW) |
homedir | () -> str | $HOME (Windows: %USERPROFILE%) |
configDir | () -> str | $XDG_CONFIG_HOME or $HOME/.config (Windows: %APPDATA%) |
dataDir | () -> str | $XDG_DATA_HOME or $HOME/.local/share (Windows: %LOCALAPPDATA%) |
cacheDir | () -> str | $XDG_CACHE_HOME or $HOME/.cache (Windows: %LOCALAPPDATA%) |
username | () -> str | Login name from the password database |
hostname | () -> str | gethostname(2) |
getpid | () -> int | Process id |
cpuCount | () -> int | Online CPUs, at least 1 |
diskTotal / diskFree | (str path) -> int | Bytes via statvfs; -1 on error |
Platform information
getSystemName, getSystemRelease, getSystemVersion, getSystemMachine, getSystemProcessor, getSystemNode — all () -> str from uname(2). getSystemArchitecture() -> str returns "64bit" or "32bit".
JSON-returning helpers:
| Function | Signature | Returns |
|---|---|---|
getSystemUname | () -> str | {system, node, release, version, machine, processor} |
getSystemInfo | () -> str | The same fields plus architecture |
getSystemDistro | () -> str | Parsed /etc/os-release, or {} |
The Python-compat getters (getPythonVersion, getPythonImplementation) and the python* fields of getSystemInfo are gone: there is no Python runtime to introspect, and a standing ""/"Lynxer" value was a lie. See removed-features.
Example
global setup(){ import("os"); }
global main(){
println(global.os.getcwd());
list entries = global.os.listdir(".");
println(returnLength(entries));
println(global.os.getSystemName());
}
See also
- stdlib-contracts — the contract this module implements, including the error sentinel family it uses.
- builtins — the functions the interpreter implements itself.
- limitations — the full divergence register.