#pragma once // FileMgr #include #include #include "FileSystem.h" namespace FileManager { class FileMgr { public: using Pattern = std::string; using Patterns = std::vector; using File = std::string; using Files = std::vector; using Dir = std::string; using Dirs = std::vector; using Path = std::string; FileMgr() { path_ = "."; patterns_.push_back("*.*"); } FileMgr(const Path& path) : path_(path) { patterns_.push_back("*.*"); } virtual ~FileMgr() {} void addPattern(const Pattern& patt) { if (patterns_.size() == 1 && patterns_[0] == "*.*") patterns_.pop_back(); patterns_.push_back(patt); } void search() { find(path_); } virtual void file(const File& file) { std::cout << "\n " << file; } virtual void dir(const Dir& dir) { std::cout << "\n " << dir; } void find(const Path& path = "") { Path fpath = path; if (path == "") fpath = path_; fpath = FileSystem::Path::getFullFileSpec(fpath); dir(fpath); for (auto patt : patterns_) { Files files = FileSystem::Directory::getFiles(fpath, patt); for (auto f : files) { file(f); } } Dirs dirs = FileSystem::Directory::getDirectories(fpath); for (auto d : dirs) { if (d == "." || d == "..") continue; Path dpath = fpath + "\\" + d; find(dpath); } } private: Path path_; Files fileSpecs_; Patterns patterns_; }; }