Advertisement
ikseek

Untitled

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