Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. // Части имен файлов по которым будем искать
  2. const std::vector<std::string> EXTENSIONS = {".png", ".jp", ".bmp", ".tiff"};
  3.  
  4. // То что найдем
  5. std::vector<std::string> gFilePathsINeed;
  6.  
  7. // Проверка соответствия имени файла нужным критериям
  8. bool needFile(const std::string& fileName)
  9. {
  10.     for(int i = 0; i < EXTENSIONS.size(); ++i)
  11.         if(fileName.find(extentions[i]) != std::string::npos)
  12.             return true;
  13.  
  14.     return false;
  15. }
  16.  
  17. // Рекурсивно ищем файлы
  18. void findFiles(const std::string& dirPath)
  19. {
  20.     std::vector<Info> files = readDir(dirPath); // readDir определена в Dir.h и Dir.cpp
  21.     for(int i = 0; i < files.size(); ++i)
  22.     {
  23.         if(it->isDir && it->fileName[0] != '.')
  24.             //Если директория и это не . или .. , то обработаем поддиректорию
  25.             findFiles(dirPath + it->fileName + '\\');
  26.         else if(needFile(it->fileName))
  27.         {
  28.             //Иначе это файл и если он нам подходит то запоминаем полный путь
  29.             gFilePathsINeed.push_back(dirPath + it->fileName);
  30.         }
  31.     }
  32. }
  33.  
  34. int main()
  35. {
  36.     findFiles("C://Pictures/Goshan/");
  37.     std::cout << "Files i need:\n\n";
  38.     for(int i = 0; i < gFilePathsINeed.size() ++i)
  39.         std::cout << gFilePathsINeed[i] << std::endl;
  40.     _getch();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement