Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Folder.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <functional>
  10. #include <memory>
  11. #include <string>
  12. #include <vector>
  13. class File {
  14. public:
  15. 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, bool casesensitive = false);
  41. private:
  42. void createFolderItems();
  43. int readFolderItems(std::vector<std::string>& foundFiles, std::vector<std::string>& foundFolders);
  44. std::string name; //!< Only last part of path
  45. std::string path; //!< Full path, with name and '/' at end
  46. bool hasListed;
  47. bool listDot;
  48. std::vector<File> files;
  49. std::vector<Folder> folders;
  50. };
  51. #endif