程序源代码:
#include <iostream>
#include <vector>
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
using namespace std;
using namespace boost::filesystem;
void scanFilesUseRecursive(const string& rootPath,vector<string>& vs)
{
path fullpath(rootPath);
if(!exists(fullpath))
{
return;
}
recursive_directory_iterator end_iter;
for(recursive_directory_iterator iter(fullpath); iter != end_iter; ++iter)
{
try
{
if (is_directory(*iter))
{
std::cout<<*iter << "is dir" << std::endl;
vs.push_back(iter->path().string());
}
else
{
vs.push_back(iter->path().string());
std::cout << *iter << " is a file" << std::endl;
}
}
catch (const std::exception & ex)
{
std::cerr << ex.what() << std::endl;
continue;
}
}
}
int main()
{
vector<string> vs;
scanFilesUseRecursive("/mywork/my_exercise", vs);
return 0;
}
Makefile源码:
all:
g++ main.cpp \
-I/usr/include/vion-base-sdk \
-I/usr/local/boost \
-L/usr/lib/vion-base-sdk \
-lSCCommon -lSCAppCommon -lSCOS \
-lboost_filesystem -lboost_system -lboost_thread \
-o test
clean:
rm test *.o -rf