Chapter summary
We use std.fs to work with the file system.
- We can create, read, and write files at absolute paths, always handling errors with try, catch, or if |err_x|.
- When writing text, we use buffers or multiline strings directly. To read, we open the file and use read with a defined buffer.
- We can get the current working directory with realpath or realpathAlloc.
- To check if a directory exists, we use openDirAbsolute or openDir from the current directory (cwd()).
- To list the contents of a directory, we use an iterator after opening it with the .iterate = true flag.
- To create or delete directories, we use makeDirAbsolute and deleteDirAbsolute.
- Always be very careful when running code that deletes or modifies files or directories. Do your tests in the /tmp/ directory to avoid losing data.