How should I use directory_iterator
to list directory files (not recursive)?
Also what header files / libs should I add/link or other settings I should make? I'm using boost in my project but by some reason directory_iterator
is "underclared identifier" while I can use other boost features.
Update
Another solution:
#include <filesystem>
#include <boost/filesystem.hpp>
#include <iostream>
using namespace boost::filesystem;
for (directory_iterator itr(path_ss); itr!=directory_iterator(); ++itr)
{
cout << itr->path().filename() << ' '; // display filename only
if (is_regular_file(itr->status())) cout << " [" << file_size(itr->path()) << ']';
cout << '
';
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…