Skip to content

fs

Reading and writing files.

Reading a file that is not there, or writing where the host does not allow it, is undefined. Call exists first.

import fs

exists

def exists(path: String) -> Bool

Tells whether there is a file at path.

Parameters

  • path: the file, relative to the directory the program runs in, or absolute.

Returns

true when the file exists, false otherwise.

Example

read_text

def read_text(path: String) -> String

Reads the whole file at path as text. Reading a file that does not exist is undefined, so check with exists first.

Parameters

  • path: the file, relative to the directory the program runs in, or absolute.

Returns

The file’s contents.

Example

write_text

def write_text(path: String, text: String) -> ()

Writes text to the file at path, replacing what it held, and creating it if it does not exist. Writing where the host does not allow it is undefined.

Parameters

  • path: the file, relative to the directory the program runs in, or absolute.
  • text: the new contents.

Example