File.hpp 2.6 KB

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