fs

Note: parts of this file are platform-conditional (#if).

File.Error: CouldNotOpen, WriteFailed, print

Functions: File.exists, File.createDirectory, File.removeDirectory, File.remove, File.rename, File.currentDirectory, File.changeDirectory, File.read, File.write, File.size, File.listDirectory

enum File.Error : Printable

An error reading or writing a file.

CouldNotOpen

CouldNotOpen

WriteFailed

WriteFailed

print

void print(OutputStream& stream)

Writes the error as text.

File.exists

bool File.exists(string path)

Returns true if a file or directory exists at the path.

File.createDirectory

bool File.createDirectory(string path)

Creates a single directory, returning true on success.

File.removeDirectory

bool File.removeDirectory(string path)

Removes an empty directory, returning true on success.

File.remove

bool File.remove(string path)

Removes the file, returning true on success.

File.rename

bool File.rename(string oldPath, string newPath)

Renames a file or directory, returning true on success.

File.currentDirectory

StringBuf File.currentDirectory()

Returns the current working directory.

File.changeDirectory

bool File.changeDirectory(string path)

Changes the current working directory, returning true on success.

File.read

Result<StringBuf, File.Error> File.read(string path)

Reads the entire file into a string, or returns an error if the file can't be opened.

File.write

File.Error? File.write(string path, string content)

Writes the string to the named file, returning null on success.

File.size

int64? File.size(string path)

Returns the size of the file, or null if it can't be opened.

File.listDirectory

List<StringBuf> File.listDirectory(string path)

Returns the names in the directory, sorted, or an empty list if it can't be opened.

Names come from the shell, so a name containing a line break is split in two.