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.

Folder.h 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*!
  2. * \file include/utils/FileSystem.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 "Exception.h"
  10. #include <functional>
  11. #include <memory>
  12. #include <string>
  13. #include <vector>
  14. class File {
  15. public:
  16. File(std::string file);
  17. std::string& getName() { return name; }
  18. std::string& getPath() { return path; }
  19. private:
  20. std::string name;
  21. std::string path;
  22. };
  23. class Folder {
  24. public:
  25. Folder(std::string folder, bool listDotFiles = false);
  26. std::string& getName() { return name; }
  27. std::string& getPath() { return path; }
  28. unsigned long fileCount();
  29. File& getFile(unsigned long i);
  30. unsigned long folderCount();
  31. Folder& getFolder(unsigned long i);
  32. Folder getParent();
  33. void executeRemoveFiles(std::function<bool (File& f)> func);
  34. void findFilesEndingWith(std::vector<File>& found, std::string end, bool casesensitive = false);
  35. // Accessing a folder recursively
  36. // This treats all files in all subfolders as if they were in this folder
  37. unsigned long countRecursiveFiles();
  38. void executeRemoveRecursiveFiles(std::function<bool (File& f)> func);
  39. std::string getRecursiveFileName(unsigned long i);
  40. File& getRecursiveFile(unsigned long i);
  41. void findRecursiveFilesEndingWith(std::vector<File>& found, std::string end, 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