如何获取给定目录中的所有文件名
答
Boost有一个伟大的平台无关filesystem library。它将使用MFC。
下面是一个例子,从their reference:
#include <iostream>
#include <filesystem>
using std::tr2::sys;
using std::cout;
int main(int argc, char* argv[])
{
std::string p(argc <= 1 ? "." : argv[1]);
if (is_directory(p))
{
for (directory_iterator itr(p); itr!=directory_iterator(); ++itr)
{
cout << itr->path().filename() << ' '; // display filename only
if (is_regular_file(itr->status())) cout << " [" << file_size(itr->path()) << ']';
cout << '\n';
}
}
else cout << (exists(p) ? "Found: " : "Not found: ") << p << '\n';
return 0;
}