Working with filesystem paths
An important addition to the C++17 standard is the filesystem
library that enables us to work with paths, files, and directories in the hierarchical filesystems (such as Windows or POSIX filesystems). This standard library has been developed based on the boost.filesystem
library. In the next few recipes, we will explore those features of the library that enable us to perform operations with files and directories, such as creating, moving, or deleting them, but also querying properties and searching. It is important, however, that we first look at how library handles paths.
Getting ready
For this recipe, we will consider most of the examples using Windows paths. In the accompanying code, all examples have both Windows and POSIX alternatives.
The filesystem
library is available in the std::filesystem
namespace in the <filesystem>
header. To simplify code, we will use the following namespace alias in all examples:
namespace fs = std::filesystem;
Note
At the...