Chapter 10: Using the File System
The purpose of the STL filesystem
library is to normalize file system operations across platforms. The filesystem
library seeks to normalize operations, bridging irregularities between POSIX/Unix, Windows, and other file systems.
The filesystem
library was adopted from the corresponding Boost library and incorporated into the STL with C++17. At the time of writing, there are still gaps in its implementation on some systems, but the recipes in this chapter have been tested on Linux, Windows, and macOS file systems, and compiled with the latest available versions of the GCC, MSVC, and Clang compilers, respectively.
The library uses the <filesystem>
header, and the std::filesystem
namespace is commonly aliased as fs
:
namespace fs = std::filesystem;
The fs::path
class is at the core of the filesystem
library. It provides normalized filename and directory path representation across disparate environments. A path
object may represent a...