Skip to content

File I/O

Methods

MethodReturnsDescription
File.read(path)stringRead entire file
File.write(path, data)Write file (overwrite)
File.append(path, data)Append to file
File.exists(path)intFile exists (1/0)
File.delete(path)Delete file
File.size(path)intFile size in bytes
File.is_file(path)intIs regular file (1/0)
File.is_dir(path)intIs 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()stringCurrent directory
File.temp_file()stringTemp 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")

MIT License