Working with filesystem paths
An important addition to the C++17 standard is the filesystem
library, which enables us to work with paths, files, and directories in 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, to first look at how this 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 the code, we will use the following namespace alias in all of the examples:
namespace...