LEARN VOID

Platform information and directories

Find the host platform or ask for the right application directory.

os-directories.voidDownload source
use os

func entry(input: i32) -> i32:
    if os.platform().length > 0:
        return input + 1
    return input
Input 4Expected result 5

Inspect the host

os.platform() returns a platform name and os.architecture() identifies the architecture. The example checks whether a name was returned so its numeric result stays portable.

Choose a directory by purpose

Use os.config_dir(app_id) for settings, data_dir for durable data and cache_dir for disposable files. Match their results. A returned path does not create a directory or grant permission to write it.

Locate bundled resources

Use os.resource_dir() for packaged resources instead of assuming the working directory is beside the executable. Environment queries and home or temporary directory lookup can fail. Keep host-specific paths out of portable configuration.

Continue learning with Files and paths.