19 #include <boost/filesystem.hpp>
26 namespace fs = boost::filesystem;
31 if (name.find(
'*') != std::string::npos) {
34 if (name.find(
'?') != std::string::npos) {
40 void glob(
const fs::path& base,
const fs::path& pattern, std::vector<std::string>& out) {
41 if (pattern.empty()) {
42 out.push_back(base.string());
46 auto it = pattern.begin();
47 auto next_part = *(it++);
48 fs::path next_pattern;
49 for (; it != pattern.end(); ++it) {
54 WIN32_FIND_DATA file_data;
55 auto search = base / next_part;
57 auto handle = FindFirstFile(search.wstring().data(), &file_data);
59 auto handle = FindFirstFile(search.string().data(), &file_data);
61 if (handle != INVALID_HANDLE_VALUE) {
63 fs::path found_part(file_data.cFileName);
64 if (!found_part.filename_is_dot() && !found_part.filename_is_dot_dot()) {
65 glob(base / found_part, next_pattern, out);
67 }
while (FindNextFile(handle, &file_data) != 0);
71 glob(base / next_part, next_pattern, out);
79 std::vector<std::string>
glob(
const std::string& pattern) {
80 std::vector<std::string> results;
81 fs::path pattern_path(pattern);
82 if (!pattern_path.empty()) {
83 ::glob(pattern_path.root_path(), pattern_path.relative_path(), results);
bool has_wildcard(const std::string &name)
std::vector< std::string > glob(const std::string &pattern)