Lyric v2.7.1

std.io.file

readText function

pub fn readText(path: string): ?string

The whole content as text, decoded as UTF-8 — bytes that are not valid UTF-8 become U+FFFD. For binary data use readBytes. null when the file does not exist or is not readable.

stdlib/std/io/file.lyr:21

writeText function

pub fn writeText(path: string, content: string): bool

Writes text (UTF-8), replacing an existing file. true on success.

stdlib/std/io/file.lyr:24

appendText function

pub fn appendText(path: string, content: string): bool

Appends to an existing file or creates it. true on success.

stdlib/std/io/file.lyr:27

exists function

pub fn exists(path: string): bool

Whether something — file or directory — exists at the path.

stdlib/std/io/file.lyr:30

remove function

pub fn remove(path: string): bool

true when the file is gone afterwards, including when it never existed.

stdlib/std/io/file.lyr:33

readBytes function

pub fn readBytes(path: string): uint8[]

The raw bytes, undecoded — what readText cannot give: its UTF-8 decoding turns invalid bytes into U+FFFD. An unreadable file reads as empty, the readLines convention; a caller that needs the difference asks exists first.

stdlib/std/io/file.lyr:38

writeBytes function

pub fn writeBytes(path: string, data: uint8[]): bool

Writes raw bytes, replacing an existing file. true on success — the writeText convention. (v1.14: the first native whose parameter is an array.)

stdlib/std/io/file.lyr:42

appendBytes function

pub fn appendBytes(path: string, data: uint8[]): bool

Appends raw bytes to an existing file or creates it. true on success.

stdlib/std/io/file.lyr:45

readLines function

pub fn readLines(path: string): string[]

The lines of a file, or an empty array when it is not readable. Terminators are removed, so whether the file used CRLF or LF is no longer visible.

stdlib/std/io/file.lyr:49

size function

pub fn size(path: string): ?int

The size in bytes, or null when the file does not exist.

stdlib/std/io/file.lyr:59

isFile function

pub fn isFile(path: string): bool

Whether the path names an existing FILE.

stdlib/std/io/file.lyr:61

isDirectory function

pub fn isDirectory(path: string): bool

Whether the path names an existing DIRECTORY.

stdlib/std/io/file.lyr:63

copy function

pub fn copy(from: string, to: string): bool

Copies. false when the source is missing or the target is not writable.

stdlib/std/io/file.lyr:66

move function

pub fn move(from: string, to: string): bool

Moves or renames; the same operation on every file system.

stdlib/std/io/file.lyr:69

createDir function

pub fn createDir(path: string): bool

Creates one directory; the parent must exist. createDirAll creates the chain.

stdlib/std/io/file.lyr:72

createDirAll function

pub fn createDirAll(path: string): bool

Creates missing parent directories too. An existing directory counts as success.

stdlib/std/io/file.lyr:75

removeDir function

pub fn removeDir(path: string): bool

Deletes an EMPTY directory. There is no recursive delete; a caller that needs one writes the loop visibly.

stdlib/std/io/file.lyr:79

listDir function

pub fn listDir(path: string): string[]

The entries of a directory: names rather than paths, sorted alphabetically.

An empty array for an unreadable directory rather than a ?string[], as in readLines. A caller that needs the difference asks isDirectory first.

stdlib/std/io/file.lyr:85

tempDir function

pub fn tempDir(): string

A path in the system's temporary directory. Does NOT create the file.

stdlib/std/io/file.lyr:88

joinPath function

pub fn joinPath(left: string, right: string): string

Joins two path parts, with neither a doubled nor a missing separator.

stdlib/std/io/file.lyr:102

fileName function

pub fn fileName(path: string): string

The last component. "a/b/c.txt" becomes "c.txt".

stdlib/std/io/file.lyr:135

parentDir function

pub fn parentDir(path: string): string

Everything before the last separator, or "" when there is none.

stdlib/std/io/file.lyr:141

extension function

pub fn extension(path: string): string

The extension WITHOUT the dot. "" when there is none.

A leading dot does not count: ".gitignore" has no extension, that is its name. This rule differs between languages, so it is stated here.

stdlib/std/io/file.lyr:157

stem function

pub fn stem(path: string): string

The name without its extension. "a/b/c.txt" becomes "c".

stdlib/std/io/file.lyr:173

withExtension function

pub fn withExtension(path: string, ext: string): string

Replaces the extension. An empty extension removes it.

stdlib/std/io/file.lyr:183

isAbsolute function

pub fn isAbsolute(path: string): bool

Does the path start at the root? Recognises /x and C:\x.

stdlib/std/io/file.lyr:191