Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Части имен файлов по которым будем искать
- const std::vector<std::string> EXTENSIONS = {".png", ".jp", ".bmp", ".tiff"};
- // То что найдем
- std::vector<std::string> gFilePathsINeed;
- // Проверка соответствия имени файла нужным критериям
- bool needFile(const std::string& fileName)
- {
- for(int i = 0; i < EXTENSIONS.size(); ++i)
- if(fileName.find(extentions[i]) != std::string::npos)
- return true;
- return false;
- }
- // Рекурсивно ищем файлы
- void findFiles(const std::string& dirPath)
- {
- std::vector<Info> files = readDir(dirPath); // readDir определена в Dir.h и Dir.cpp
- for(int i = 0; i < files.size(); ++i)
- {
- if(it->isDir && it->fileName[0] != '.')
- //Если директория и это не . или .. , то обработаем поддиректорию
- findFiles(dirPath + it->fileName + '\\');
- else if(needFile(it->fileName))
- {
- //Иначе это файл и если он нам подходит то запоминаем полный путь
- gFilePathsINeed.push_back(dirPath + it->fileName);
- }
- }
- }
- int main()
- {
- findFiles("C://Pictures/Goshan/");
- std::cout << "Files i need:\n\n";
- for(int i = 0; i < gFilePathsINeed.size() ++i)
- std::cout << gFilePathsINeed[i] << std::endl;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement