include iostream include filesystem include cxxopts hpp namespace fs s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <filesystem>
#include <cxxopts.hpp>
namespace fs = std::filesystem;
int main(int argc, char** argv)
{
auto options = cxxopts::Options{"c++20", "find files with std::ends_with"};
options.add_options()
("e,ext", "filename extension",
cxxopts::value<std::string>()->default_value("cpp"));
auto result = options.parse(argc, argv);
auto extension = result["ext"].as<std::string>();
for(const auto& p: fs::recursive_directory_iterator(fs::current_path()))
{
if (p.path().string().ends_with(extension))
{
std::cout << p << '\n';
}
}
}