Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*!
  2. * \file include/utils/Folder.h
  3. * \brief Recursive file-system walking utilities
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _UTILS_FOLDER_H_
  8. #define _UTILS_FOLDER_H_
  9. #include <functional>
  10. #include <memory>
  11. #include <string>
  12. #include <vector>
  13. class File {
  14. public:
  15. explicit File(std::string file);
  16. std::string& getName() { return name; }
  17. std::string& getPath() { return path; }
  18. private:
  19. std::string name;
  20. std::string path;
  21. };
  22. class Folder {
  23. public:
  24. Folder(std::string folder, bool listDotFiles = false);
  25. std::string& getName() { return name; }
  26. std::string& getPath() { return path; }
  27. unsigned long fileCount();
  28. File& getFile(unsigned long i);
  29. unsigned long folderCount();
  30. Folder& getFolder(unsigned long i);
  31. Folder getParent();
  32. void executeRemoveFiles(std::function<bool (File& f)> func);
  33. void findFilesEndingWith(std::vector<File>& found, std::string end, bool casesensitive = false);
  34. // Accessing a folder recursively
  35. // This treats all files in all subfolders as if they were in this folder
  36. unsigned long countRecursiveFiles();
  37. void executeRemoveRecursiveFiles(std::function<bool (File& f)> func);
  38. std::string getRecursiveFileName(unsigned long i);
  39. File& getRecursiveFile(unsigned long i);
  40. void findRecursiveFilesEndingWith(std::vector<File>& found, std::string end,
  41. bool casesensitive = false);
  42. private:
  43. void createFolderItems();
  44. int readFolderItems(std::vector<std::string>& foundFiles, std::vector<std::string>& foundFolders);
  45. std::string name; //!< Only last part of path
  46. std::string path; //!< Full path, with name and '/' at end
  47. bool hasListed;
  48. bool listDot;
  49. std::vector<File> files;
  50. std::vector<Folder> folders;
  51. };
  52. #endif