utils.h 680 B

123456789101112131415161718192021222324252627
  1. #include <string>
  2. #include <vector>
  3. #include "iostream"
  4. #include <fstream>
  5. #include <iostream>
  6. #include <sstream>
  7. #include <glob.h>
  8. std::vector<std::string> glob(const std::string pattern)
  9. {
  10. std::vector<std::string> filenames;
  11. using namespace std;
  12. glob_t glob_result;
  13. memset(&glob_result, 0, sizeof(glob_result));
  14. int return_value = glob(pattern.c_str(), GLOB_TILDE, NULL, &glob_result);
  15. if(return_value != 0){
  16. globfree(&glob_result);
  17. return filenames;
  18. }
  19. for(auto idx =0; idx <glob_result.gl_pathc; idx++){
  20. filenames.push_back(string(glob_result.gl_pathv[idx]));
  21. }
  22. globfree(&glob_result);
  23. return filenames;
  24. }