File.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-15
  6. * Changed: 2020-08-16
  7. *
  8. * */
  9. #ifndef FILE_HPP
  10. #define FILE_HPP
  11. #include "../base/Class.hpp"
  12. #include <string>
  13. #include <vector>
  14. #include <ctime>
  15. namespace ls_std {
  16. class File : public Class {
  17. public:
  18. explicit File(std::string _absoluteFilePath);
  19. ~File() = default;
  20. // comparison operators
  21. bool operator==(File& _file);
  22. bool operator!=(File& _file);
  23. // additional functionality
  24. bool canExecute();
  25. void createNewFile();
  26. bool exists();
  27. std::string getAbsoluteFilePath();
  28. std::string getName();
  29. std::string getParent();
  30. long getSize();
  31. bool isDirectory();
  32. bool isFile();
  33. time_t lastModified();
  34. void makeDirectory();
  35. void makeDirectories();
  36. void remove();
  37. private:
  38. std::string absoluteFilePath {};
  39. bool _exists(const std::string& _path);
  40. bool _isDirectory(const std::string& _path);
  41. bool _isFile(const std::string& _path);
  42. static time_t _lastModified(const std::string& _path);
  43. static int _mkdir(const std::string& _path);
  44. static std::string _normalizePath(std::string _path);
  45. static std::vector<std::string> _splitIntoSubDirectoryNames(const std::string& _path);
  46. };
  47. }
  48. #endif