std::filesystem::path
Represents a filesystem path in a cross-platform way, handling differences between operating systems automatically. Can be constructed from a string and supports path operations like appending with /. Part of the std::filesystem library introduced in C++17. std::filesystem::remove_all()
Removes a file OR a directory plus all of its contents recursively. Returns the number of files and directories removed. Accepts an optional std::error_code parameter to handle errors without throwing exceptions. std::filesystem::exists
Checks whether a file or directory exists at the given path. Returns true if something exists at that path, false if it doesn't. Commonly used in tests to verify files were created or deleted. |
std::filesystem::permissions
Sets the access permissions on a file or directory. Permissions control who can read, write, or execute a file. Uses std::filesystem::perms flags combined with | to set multiple permissions at once. std::filesystem::create_directories()
Creates a directory and any missing parent directories in the path. Does nothing if the directory already exists. Use create_directory() instead if you only need to create a single directory with an existing parent. |
std::filesystem::temp_directory_path()
Returns the path to the system's temporary directory. On Linux this is typically /tmp, on Windows it's usually C:\Users\username\AppData\Local\Temp. Useful for creating temporary files and directories during tests that won't interfere with the real filesystem. std::filesystem::path::string()
Converts a std::filesystem::path to a std::string. Necessary when passing a path to functions that expect a plain string rather than a fs::path object. Returns the path as a native string representation for the current operating system. |
Cheatography
https://cheatography.com
C++ (std::filesystem) Cheat Sheet (DRAFT) by blakecromar
A cheatsheet for for std::filesystem
This is a draft cheat sheet. It is a work in progress and is not finished yet.