std.io.file
text function
pub fn text(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 bytes. null when the file does not exist or is not readable.
stdlib/std/io/file.lyr:40
bytes function
pub fn bytes(path: string): ?uint8[]
The raw bytes, undecoded — what text cannot give: its UTF-8 decoding turns invalid bytes
into U+FFFD. null when the file is not readable; an EMPTY array is an empty file.
stdlib/std/io/file.lyr:44
lines function
pub fn lines(path: string): ?string[]
The lines of a file, terminators removed, so whether the file used CRLF or LF is no longer
visible. null when the file is not readable; an EMPTY array is an empty file.
stdlib/std/io/file.lyr:48
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:51
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:54
exists function
pub fn exists(path: string): bool
Whether something — file or directory — exists at the path.
stdlib/std/io/file.lyr:57
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:60
readBytes function
pub fn readBytes(path: string): uint8[]
Deprecated: use bytes, which distinguishes an empty file from an unreadable one.
stdlib/std/io/file.lyr:63
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:70
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:73
readLines function
pub fn readLines(path: string): string[]
Deprecated: use lines, which distinguishes an empty file from an unreadable one.
stdlib/std/io/file.lyr:76
readText function
pub fn readText(path: string): ?string
Deprecated: use text. Same answer, one name for the same idea across the module.
stdlib/std/io/file.lyr:82
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:92
isFile function
pub fn isFile(path: string): bool
Whether the path names an existing FILE.
stdlib/std/io/file.lyr:94
isDirectory function
pub fn isDirectory(path: string): bool
Whether the path names an existing DIRECTORY.
stdlib/std/io/file.lyr:96
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:99
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:102
createDir function
pub fn createDir(path: string): bool
Creates one directory; the parent must exist. createDirAll creates the chain.
stdlib/std/io/file.lyr:105
createDirAll function
pub fn createDirAll(path: string): bool
Creates missing parent directories too. An existing directory counts as success.
stdlib/std/io/file.lyr:108
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:112
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:118
tempDir function
pub fn tempDir(): string
A path in the system's temporary directory. Does NOT create the file.
stdlib/std/io/file.lyr:121
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:135
fileName function
pub fn fileName(path: string): string
The last component. "a/b/c.txt" becomes "c.txt".
stdlib/std/io/file.lyr:168
parentDir function
pub fn parentDir(path: string): string
Everything before the last separator, or "" when there is none.
stdlib/std/io/file.lyr:174
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:190
stem function
pub fn stem(path: string): string
The name without its extension. "a/b/c.txt" becomes "c".
stdlib/std/io/file.lyr:206
withExtension function
pub fn withExtension(path: string, ext: string): string
Replaces the extension. An empty extension removes it.
stdlib/std/io/file.lyr:216
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:224