File.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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-17
  7. *
  8. * */
  9. #ifndef FILE_HPP
  10. #define FILE_HPP
  11. #include "../base/Class.hpp"
  12. #include <string>
  13. #include <vector>
  14. #include <list>
  15. #include <ctime>
  16. #ifdef _WIN32
  17. #include <windows.h>
  18. #endif
  19. namespace ls_std {
  20. class File : public Class {
  21. public:
  22. explicit File(std::string _absoluteFilePath);
  23. ~File() = default;
  24. // comparison operators
  25. bool operator==(File& _file);
  26. bool operator!=(File& _file);
  27. // additional functionality
  28. bool canExecute();
  29. void createNewFile();
  30. bool exists();
  31. std::string getAbsoluteFilePath();
  32. std::string getName();
  33. std::string getParent();
  34. long getSize();
  35. bool isDirectory();
  36. bool isFile();
  37. time_t lastModified();
  38. std::list<std::string> list();
  39. std::list<std::string> listFiles();
  40. void makeDirectory();
  41. void makeDirectories();
  42. void remove();
  43. private:
  44. std::string absoluteFilePath {};
  45. #ifdef _WIN32
  46. static void _addToFileListWindows(const std::string& _path, bool _withDirectories, WIN32_FIND_DATA _data, std::list<std::string>& _list);
  47. #endif
  48. static bool _exists(const std::string& _path);
  49. static std::string _getParent(const std::string& _path);
  50. static bool _isDirectory(const std::string& _path);
  51. static bool _isFile(const std::string& _path);
  52. static time_t _lastModified(const std::string& _path);
  53. static std::list<std::string> _list(const std::string& _path);
  54. static std::list<std::string> _listFiles(const std::string& _path);
  55. #if defined(unix) || defined(__APPLE__)
  56. static std::list<std::string> _listUnix(const std::string& _path, bool withDirectories);
  57. #endif
  58. #ifdef _WIN32
  59. static std::list<std::string> _listWindows(const std::string& _path, bool withDirectories);
  60. #endif
  61. static int _mkdir(const std::string& _path);
  62. static std::string _normalizePath(std::string _path);
  63. static std::vector<std::string> _splitIntoSubDirectoryNames(const std::string& _path);
  64. };
  65. }
  66. #endif