File I/O
Methods
| Method | Returns | Description |
|---|---|---|
File.read(path) | string | Read entire file |
File.write(path, data) | Write file (overwrite) | |
File.append(path, data) | Append to file | |
File.exists(path) | int | File exists (1/0) |
File.delete(path) | Delete file | |
File.size(path) | int | File size in bytes |
File.is_file(path) | int | Is regular file (1/0) |
File.is_dir(path) | int | Is directory (1/0) |
File.rename(old, new) | Rename/move | |
File.copy(src, dst) | Copy file | |
File.mkdir(path) | Create directory | |
File.list_dir(path) | [string] | List directory |
File.cwd() | string | Current directory |
File.temp_file() | string | Temp file path |
Examples
wyn
// Write and read
File.write("/tmp/hello.txt", "Hello, Wyn!")
var content = File.read("/tmp/hello.txt")
println(content) // Hello, Wyn!
// Append
File.append("/tmp/hello.txt", "\nLine 2")
// Check existence
if File.exists("/tmp/hello.txt") {
println("size: ${File.size("/tmp/hello.txt")}")
}
// Cleanup
File.delete("/tmp/hello.txt")