Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. wstring FolderPathValidator::FindRequiredFolder(const wstring& p_InitialPath, wstring p_RequiredFolderName)
  2. {
  3. wstring foundFolder = L"";
  4. wstring folderPath = p_InitialPath + L"\*";
  5. WIN32_FIND_DATAW folderInfo;
  6. HANDLE search_handle = FindFirstFileW(folderPath.c_str(), &folderInfo);
  7. if (search_handle != INVALID_HANDLE_VALUE)
  8. {
  9. vector<wstring> folders;
  10.  
  11. do
  12. {
  13. if (folderInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  14. {
  15. if ((!lstrcmpW(folderInfo.cFileName, L".")) || (!lstrcmpW(folderInfo.cFileName, L"..")))
  16. continue;
  17. }
  18.  
  19. folderPath = p_InitialPath + L"\" + wstring(folderInfo.cFileName);
  20.  
  21. if (folderInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  22. {
  23. if (folderInfo.cFileName == p_RequiredFolderName)
  24. {
  25. foundFolder = folderInfo.cFileName;
  26. return foundFolder;
  27. }
  28. folders.push_back(folderPath);
  29. }
  30. } while (FindNextFileW(search_handle, &folderInfo));
  31.  
  32. ::FindClose(search_handle);
  33.  
  34. for (vector<wstring>::iterator iter = folders.begin(), end = folders.end(); iter != end; ++iter)
  35. FindRequiredFolder(*iter, p_RequiredFolderName);
  36. }
  37.  
  38. return foundFolder;
  39. }
  40.  
  41. wstring FoundFolder = FindRequiredFolder(L"C:", L"TextFiles_to_Test");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement