File

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

Filepaths may be absolute (/) or relative (./ or ../). The default encoding is UTF-8.

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 call Sparkle's File's read with just "./hello/world.txt"

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

Synchronously writes a string to a file.

let content be call Sparkle's File's read with just "./hello/world.txt"

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

Synchronously appends a string to the end of a file.

let content be call Sparkle's File's read with just "./hello/world.txt"

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

Returns true if a file exists at the specified path.

if call Sparkle's File's file_exists with just "./hello/world.txt" do
  print "file exists"
otherwise
  print "file does not exist"

Synchronously creates an empty file at the specified path.

call Sparkle's File's create_file with just "./hello/world.txt"

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

Synchronously deletes the file at the specified path.

call Sparkle's File's delete_file with just "./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 call Sparkle's File's directory_exists with just "./hello/world.txt" do
  print "directory exists"
otherwise
  print "directory does not exist"

Synchronously creates an empty directory at the specified path.

call Sparkle's File's create_directory with just "./hello"

Recursively creates parent directories if they don't exist.

Synchronously deletes the directory at the specified path.

call Sparkle's File's delete_directory with just "./hello"

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