Skip to main content

Reading and writing files

main.w
bring fs;

let filename: str = "/tmp/test.txt";

log(fs.exists(filename));

fs.writeFile(filename, "hello world!");
fs.exists(filename);

let file: str = fs.readFile(filename);

log(file);
log(fs.extension(filename) ?? "");
log(fs.isDir(filename));

fs.appendFile(filename, "testing");

let extendedValue = fs.readFile(filename);

log(extendedValue);
Wing console output
# Run locally with wing console
true
hello world!
txt
false
hello world!testing