Advertisement
ikseek

Untitled

Oct 26th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. void find_recursive(const wstring &pathIn, const wstring &ext, vector<wstring>& results) {
  2.     static const wstring kThisDir=L".";
  3.     static const wstring kParentDir=L"..";
  4.     const wstring prefix = pathIn + L"\\";
  5.     const wstring allFiles = prefix + L"*.*";
  6.  
  7.  
  8.     WIN32_FIND_DATA findData;
  9.     HANDLE hFind = FindFirstFile(allFiles.c_str(), &findData);
  10.     if(hFind == INVALID_HANDLE_VALUE) throw std::runtime_error("Error searching in directory");
  11.  
  12.     while(FindNextFile(hFind , &findData) != 0) {
  13.         if(findData.cFileName == kThisDir || findData.cFileName == kParentDir) {
  14.             continue;
  15.         }
  16.         if(FILE_ATTRIBUTE_DIRECTORY & findData.dwFileAttributes){
  17.             get_path_pdn(prefix + findData.cFileName, results);
  18.         }
  19.         else {
  20.             wstring foundFile = findData.cFileName;
  21.             if(foundFile.substr(foundFile.length() - ext.length()) == ext) {
  22.                 results.push_back(prefix + foundFile)
  23.             }
  24.         }
  25.     }
  26.  
  27.  
  28.     DWORD dwError = GetLastError();
  29.     if (dwError != ERROR_NO_MORE_FILES) {
  30.         wstring Error;
  31.         Error += L"FindNextFile error. Error is ";
  32.         Error += dwError;
  33.         wcout << Error;
  34.     }
  35.     FindClose(hFind);
  36. }
  37.  
  38. vector<wstring> get_path_pdn(const wstring &pathIn) {
  39.     std::vector<wstring> result;
  40.     find_recursive(pathIn, L".pdn", result)
  41.     return result;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement