Kronos
Standard Library

File I/O

Reading and writing files in Kronos

File I/O

Kronos provides built-in functions for file operations. These are available globally — no imports needed.

All file operations can throw errors. Wrap them in try/catch for robust code.


Reading Files

read_file

Read the entire contents of a file as a string.

Prop

Type

set content to call read_file with "data.txt"
print content


read_lines

Read a file and return a list of lines.

Prop

Type

set lines to call read_lines with "data.txt"

for line in lines:
    print line

Writing Files

write_file

Write content to a file. Creates the file if it doesn't exist, overwrites if it does.

Prop

Type

call write_file with "output.txt", "Hello, World!"

This overwrites existing files. There's no append mode yet.


File Information

file_exists

Check if a file or directory exists.

Prop

Type

if call file_exists with "config.txt":
    print "Config found!"
else:
    print "Using defaults..."

list_files

List all files in a directory.

Prop

Type

set files to call list_files with "."

for file in files:
    print file

Path Operations

join_path

Join path components with the appropriate separator.

set full to call join_path with "dir", "file.txt"
# Returns: "dir/file.txt"

set nested to call join_path with "/path/to", "file.txt"
# Returns: "/path/to/file.txt"

dirname

Get the directory portion of a path.

set dir to call dirname with "/path/to/file.txt"
# Returns: "/path/to"

set dir2 to call dirname with "file.txt"
# Returns: "."

basename

Get the filename portion of a path.

set file to call basename with "/path/to/file.txt"
# Returns: "file.txt"

Common Patterns

On this page