Enumerating the content of a directory
So far in this chapter, we have looked at many of the functionalities provided by the filesystem
library, such as working with paths, performing operations with files and directories (creating, moving, renaming, deleting, and so on), and querying or modifying properties. Another useful functionality when working with the filesystem is to iterate through the content of a directory. The filesystem
library provides two directory iterators, one called directory_iterator
, which iterates the content of a directory, and one called recursive_directory_iterator
, which recursively iterates the content of a directory and its subdirectories. In this recipe, we will learn how to use them.
Getting ready
For this recipe, we will consider a directory with the following structure:
test/
├──data/
│ ├──input.dat
│ └──output.dat
├──file_1.txt
├─...