Skip to content

os

This content is for v1.0. Switch to the latest version for up-to-date documentation.

The os namespace provides metadata about the underlying host platform and operating system. No import is required.


Function / PropertySignatureReturn TypeDescription
os.nameos.name()stringReturns host OS name ("windows", "linux", "macos").
os.archos.arch()stringReturns processor architecture ("x86_64", "x86", "arm64", "arm").
os.cwdos.cwd()stringReturns current working directory path.
os.chdiros.chdir(path)boolChanges current working directory. Returns true on success.
os.homeos.home()stringReturns current user’s home directory path.
os.tempos.temp()stringReturns system temporary directory path.
os.sepos.sep()stringReturns filesystem path separator (\ on Windows, / on Linux/macOS).
os.existsos.exists(path)boolChecks if path exists on disk.
os.is_diros.is_dir(path)boolReturns true if path exists and is a directory.
os.is_fileos.is_file(path)boolReturns true if path exists and is a regular file.

Detect operating system and CPU architecture for cross-platform logic:

var platform = os.name();
var arch = os.arch();
print("Running on: " + platform + " (" + arch + ")");
if (platform == "windows") {
print("Windows initialization...");
} else if (platform == "linux") {
print("Linux initialization...");
} else {
print("POSIX / Unix initialization...");
}

Inspect and modify the current working directory of the process:

print("Current dir: " + os.cwd());
if (os.chdir("..")) {
print("Moved to parent dir: " + os.cwd());
}

Get system directories in a cross-platform manner:

var userHome = os.home();
var tmpDir = os.temp();
print("User home: " + userHome);
print("Temporary directory: " + tmpDir);

os.exists(path), os.is_dir(path), os.is_file(path)

Section titled “os.exists(path), os.is_dir(path), os.is_file(path)”

Path validation and inspection:

var target = path.join(os.home(), ".config");
if (os.exists(target)) {
if (os.is_dir(target)) {
print(".config is a directory");
} else if (os.is_file(target)) {
print(".config is a file");
}
}