FileSystem

The FileSystem class provides static functions to interact with the file system.

Filepaths may be absolute (/) or relative (./ or ../).

if FileSystem's file_exists "./hello/world.txt" then
  print "file exists"
otherwise
  print "file does not exist"

Note that / is used in paths regardless of the operating system. Do not use \ to delimit paths.

Static Functions

Synchronously reads a file and returns its contents as a string.

let content be FileSystem's read "./hello/world.txt"

Errors if the file or its parent directories do not exist.

Synchronously writes a string to a file.

FileSystem's write with "./hello/world.txt", and "hello world"

Recursively creates parent directories and the file itself if they don't exist.

Synchronously appends a string to the end of a file.

FileSystem's append with "./hello/world.txt", and "hello world"

Recursively creates parent directories and the file itself if they don't exist.

Returns true if a file exists at the specified path.

if FileSystem's file_exists "./hello/world.txt" do
  print "file exists"
otherwise
  print "file does not exist"

Synchronously creates an empty file at the specified path.

FileSystem's create_file "./hello/world.txt"

Recursively creates parent directories and the file itself if they don't exist.

Errors if the file already exists.

Synchronously deletes the file at the specified path.

FileSystem's delete_file "./hello/world.txt"

Errors if the file or its parent directories do not exist.

Returns true if a directory exists at the specified path.

if FileSystem's directory_exists "./hello/world.txt" then
  print "directory exists"
otherwise
  print "directory does not exist"

Synchronously creates an empty directory at the specified path.

FileSystem's create_directory "./hello"

Recursively creates parent directories if they don't exist.

Synchronously deletes the directory at the specified path.

FileSystem's delete_directory "./hello"

Errors if the directory or its parent directories do not exist.

print "hello world"