1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <iostream>
#include <algorithm>
#include <boost/filesystem.hpp>
#include <boost/iterator/filter_iterator.hpp>
#include <functional>
namespace bfs = boost::filesystem;
template<class command_t_>
void parse(bfs::path path_, command_t_ cmd_)
{
// gestion des répertoires :
std::for_each(
boost::make_filter_iterator<bool (*)( const bfs::path & ph )>(
bfs::is_directory
,bfs::directory_iterator(path_),bfs::directory_iterator()
)
,boost::make_filter_iterator<bool (*)( const bfs::path & ph )>(
bfs::is_directory
,bfs::directory_iterator(path_),bfs::directory_iterator()
)
,std::bind2nd(std::ptr_fun(parse<command_t_>),cmd_)
);
// gestion des fichiers :
std::for_each(
boost::make_filter_iterator<bool (*)( const bfs::path & ph )>(
bfs::is_regular_file
,bfs::directory_iterator(path_),bfs::directory_iterator()
)
,boost::make_filter_iterator<bool (*)( const bfs::path & ph )>(
bfs::is_regular_file
,bfs::directory_iterator(path_),bfs::directory_iterator()
)
,cmd_
);
}
void dump_file(bfs::path const& path_)
{
assert(bfs::is_regular_file(path_));
std::cout<<path_<<"\n";
}
int main(int argc, char* argv[])
{
parse(argv[1],dump_file);
return 0;
} |
Partager