以下代码以递归方式迭代给定目录,并每次以相同顺序打印其内容。
是否可以改变目录迭代器以随机方式打印目录内容(不使用向量来存储结果然后随机打印矢量内容)?
#include <string>
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
int main(int argc, char** argv)
{
boost::filesystem::path dataPath("/home/test/");
boost::filesystem::recursive_directory_iterator endIterator;
// Traverse the filesystem and retrieve the name of each root object found
if (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) {
for (static boost::filesystem::recursive_directory_iterator directoryIterator(dataPath); directoryIterator != endIterator;
++directoryIterator) {
if (boost::filesystem::is_regular_file(directoryIterator->status())) {
std::string str = directoryIterator->path().string();
cout << str << endl;
}
}
}
}