Skip to content

Instantly share code, notes, and snippets.

@lucianmachado
Created June 26, 2015 16:18
Show Gist options
  • Save lucianmachado/9a26d5745497ffe5d054 to your computer and use it in GitHub Desktop.
Save lucianmachado/9a26d5745497ffe5d054 to your computer and use it in GitHub Desktop.
Glob C++
#include <glob.h>
#include <vector>
#include <string>
inline std::vector<std::string> glob(const std::string& pat){
using namespace std;
glob_t glob_result;
glob(pat.c_str(),GLOB_TILDE,NULL,&glob_result);
vector<string> ret;
for(unsigned int i=0;i<glob_result.gl_pathc;++i){
ret.push_back(string(glob_result.gl_pathv[i]));
}
globfree(&glob_result);
return ret;
}
@epiception
Copy link

Could this be updated to check for errors, similar to this link: https://stackoverflow.com/questions/8401777/simple-glob-in-c-on-unix-system

@cxw42
Copy link

cxw42 commented Nov 12, 2020

Thank you - this looks very useful! What is the license?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment