Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void find_recursive(const wstring &pathIn, const wstring &ext, vector<wstring>& results) {
- static const wstring kThisDir=L".";
- static const wstring kParentDir=L"..";
- const wstring prefix = pathIn + L"\\";
- const wstring allFiles = prefix + L"*.*";
- WIN32_FIND_DATA findData;
- HANDLE hFind = FindFirstFile(allFiles.c_str(), &findData);
- if(hFind == INVALID_HANDLE_VALUE) throw std::runtime_error("Error searching in directory");
- while(FindNextFile(hFind , &findData) != 0) {
- if(findData.cFileName == kThisDir || findData.cFileName == kParentDir) {
- continue;
- }
- if(FILE_ATTRIBUTE_DIRECTORY & findData.dwFileAttributes){
- get_path_pdn(prefix + findData.cFileName, results);
- }
- else {
- wstring foundFile = findData.cFileName;
- if(foundFile.substr(foundFile.length() - ext.length()) == ext) {
- results.push_back(prefix + foundFile)
- }
- }
- }
- DWORD dwError = GetLastError();
- if (dwError != ERROR_NO_MORE_FILES) {
- wstring Error;
- Error += L"FindNextFile error. Error is ";
- Error += dwError;
- wcout << Error;
- }
- FindClose(hFind);
- }
- vector<wstring> get_path_pdn(const wstring &pathIn) {
- std::vector<wstring> result;
- find_recursive(pathIn, L".pdn", result)
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement