Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. std::vector<std::string> get_all_files_names_within_folder(std::string folder) {
  2.  
  3. std::vector<std::string> names;
  4. std::string search_path = folder + "/*.*";
  5. std::string fullFilename;
  6. WIN32_FIND_DATA fd;
  7. HANDLE hFind = ::FindFirstFile(search_path.c_str(), &fd);
  8.  
  9. if (hFind != INVALID_HANDLE_VALUE) {
  10. int index = 0;
  11. do {
  12. if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  13. fullFilename = fd.cFileName;
  14. // we not save jpg files
  15. if (fullFilename.substr(fullFilename.find_last_of(".") + 1).find("jpg") == std::string::npos) {
  16. std::string fullname = folder;
  17. fullname.append(fd.cFileName);
  18. names.push_back(fullname);
  19. }
  20.  
  21. }
  22. } while (::FindNextFile(hFind, &fd));
  23.  
  24. ::FindClose(hFind);
  25. const size_t last_slash_idx = folder.find_last_of("\\/");
  26.  
  27. if (std::string::npos != last_slash_idx)
  28. {
  29. folder.erase(0, last_slash_idx + 1);
  30. }
  31.  
  32. return names;
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement