std::fsFile system operations.
Read, write, and query files on the local file system.
import std::fs;
fn main() {
let contents = fs.read("config.toml");
fs.write("output.txt", "hello");
if fs.exists("data.csv") {
let size = fs.size("data.csv");
println(size);
}
}
readRead the entire contents of a file as a UTF-8 string.
Panics if the file does not exist or cannot be read.
let src = fs.read("main.hew");
writeWrite a string to a file, creating or overwriting it.
Returns 0 on success, non-zero on error.
appendAppend a string to the end of a file.
Creates the file if it does not exist. Returns 0 on success.
existsCheck whether a file exists at the given path.
if fs.exists("config.toml") {
println("found config");
}
deleteDelete a file. Returns 0 on success.
sizeReturns the size of a file in bytes.
read_lineRead a single line from standard input.
Blocks until the user presses Enter.
print("Name: ");
let name = fs.read_line();
read_bytesRead the raw bytes of a file into a bytes value.
Returns an empty bytes buffer on error.
let data = fs.read_bytes("image.png");
println(data.len());
write_bytesWrite a bytes value to a file, creating or overwriting it.
Returns 0 on success, non-zero on error.
mkdirCreate a directory. Returns 0 on success, -1 on error.
Fails if any parent directory does not exist. Use mkdir_all to create
parent directories automatically.
mkdir_allCreate a directory and all its parent components.
Returns 0 on success, -1 on error.
list_dirList the entries in a directory.
Returns a list of entry names (not full paths). Returns an empty list on error.
let entries = fs.list_dir("/tmp");
for entry in entries {
println(entry);
}
renameRename or move a file or directory.
Returns 0 on success, -1 on error.
copyCopy a file.
Returns 0 on success, -1 on error.
is_dirCheck whether a path is a directory.