Created
July 14, 2014 04:55
-
-
Save justinvanwinkle/f6e7b0baf87dbf7dc1ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline vector<string> glob(string pattern, bool only_files = false) { | |
unique_ptr<glob_t, decltype(&globfree)> glob_buffer(new glob_t(), globfree); | |
glob(pattern.c_str(), GLOB_TILDE, NULL, glob_buffer.get()); | |
strings fns; | |
for (size_t i = 0; i < glob_buffer->gl_pathc; ++i) { | |
fns.push_back(string(glob_buffer->gl_pathv[i])); | |
} | |
if (only_files) { | |
strings file_fns; | |
for (auto &fn : fns) { | |
if (not is_dir(fn)) | |
file_fns.push_back(fn); | |
} | |
return file_fns; | |
} | |
return fns; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment