Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. std::vector<char*> Directory::getFiles(){
  2. if (dirPath[0] == 0)
  3. return{};
  4. HANDLE dir;
  5. WIN32_FIND_DATA file_data;
  6. std::vector<char*> files;
  7. char* direction = new char[strlen(dirPath) + 1];
  8. strcpy_s(direction, strlen(dirPath) + strlen("*"), dirPath);
  9. strcat_s(direction, strlen(dirPath) + strlen("*") + 1, "*");
  10. if ((dir = FindFirstFile(to_wchar(direction), &file_data)) == INVALID_HANDLE_VALUE){
  11. std::cout << "invalid handle!" << std::endl;
  12. return{};
  13. }
  14. do{
  15. char* file_name = to_char(file_data.cFileName);
  16. bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
  17. size_t size = strlen(dirPath) + strlen(file_name);
  18. char* full_file_name;
  19. full_file_name = (char*)malloc(size + 1);
  20. strcpy_s(full_file_name, size, dirPath);
  21. strcat_s(full_file_name, size + 1, file_name);
  22. if (file_name[0] == '.' || is_directory)
  23. continue;
  24. if ((file_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || (file_data.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM))
  25. continue;
  26. files.push_back(full_file_name);
  27. } while (FindNextFile(dir, &file_data));
  28. return files;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement