Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<char*> Directory::getFiles(){
- if (dirPath[0] == 0)
- return{};
- HANDLE dir;
- WIN32_FIND_DATA file_data;
- std::vector<char*> files;
- char* direction = new char[strlen(dirPath) + 1];
- strcpy_s(direction, strlen(dirPath) + strlen("*"), dirPath);
- strcat_s(direction, strlen(dirPath) + strlen("*") + 1, "*");
- if ((dir = FindFirstFile(to_wchar(direction), &file_data)) == INVALID_HANDLE_VALUE){
- std::cout << "invalid handle!" << std::endl;
- return{};
- }
- do{
- char* file_name = to_char(file_data.cFileName);
- bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
- size_t size = strlen(dirPath) + strlen(file_name);
- char* full_file_name;
- full_file_name = (char*)malloc(size + 1);
- strcpy_s(full_file_name, size, dirPath);
- strcat_s(full_file_name, size + 1, file_name);
- if (file_name[0] == '.' || is_directory)
- continue;
- if ((file_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || (file_data.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM))
- continue;
- files.push_back(full_file_name);
- } while (FindNextFile(dir, &file_data));
- return files;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement