C ++ 17 теперь имеет std::filesystem::directory_iterator
, который может использоваться как
#include
#include
#include
namespace fs = std::filesystem;
int main()
{
std::string path = "/path/to/directory";
for (const auto & p : fs::directory_iterator(path))
std::cout << p << std::endl; // "p" is the directory entry. Get the path with "p.path()".
}
. Кроме того, std::filesystem::recursive_directory_iterator
может выполнять итерацию в подкаталогах.