Chapter 8. Filename pattern globbing

#include <x/glob.H>

x::glob globber(x::glob::create());

globber->expand("/bin/*")->expand("/usr/bin/*");

std::vector<std::string> filenames;

filenames->get(std::back_insert_iterator<std::vector<std::string> >(buf));

x::glob is a reference-counted object that implements filename expansion using glob(3). The expand() function performs filename expansion. expand() takes an optional parameter that specifies the bitwise-ored options described in the glob(3) manual page. Do not specify the GLOB_DOOFFS and GLOB_ALTDIRFUNC options, as they are meaningless in this case. Do not specify GLOB_APPEND, this option gets supplied automatically when invoking expand() more than once.

get() retrieves the accumulated list of expanded filenames. This template function takes an output iterator, as shown in the above example. Specialized definitions of get() take std::vector<std::string> or a std::set<std::string> instead of an output iterator. The accumulated list of expanded filenames get added to the existing contents of the passed container.