How to do it...

In this section, we will implement a little tool that lists all files in any user provided directory. It will not only list the filenames, but also their type, size, and access permissions.

  1. First, we need to include some headers and declare that we use the namespaces std and filesystem by default.
      #include <iostream>      #include <sstream>      #include <iomanip>      #include <numeric>      #include <algorithm>      #include <vector>      #include <filesystem>            using namespace std;      using namespace filesystem;
  1. One helper function that we are going to need is file_info. It accepts a directory_entry object reference and extracts the path from it, as well as a file_status object (using the status function), which contains file type and permission information. ...

Get C++17 STL Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.