CFileInfo.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "StdInc.h"
  2. #include "CFileInfo.h"
  3. CFileInfo::CFileInfo() : name("")
  4. {
  5. }
  6. CFileInfo::CFileInfo(std::string name)
  7. : name(std::move(name))
  8. {
  9. }
  10. bool CFileInfo::exists() const
  11. {
  12. return boost::filesystem::exists(name);
  13. }
  14. bool CFileInfo::isDirectory() const
  15. {
  16. return boost::filesystem::is_directory(name);
  17. }
  18. void CFileInfo::setName(const std::string & name)
  19. {
  20. this->name = name;
  21. }
  22. std::string CFileInfo::getName() const
  23. {
  24. return name;
  25. }
  26. std::string CFileInfo::getPath() const
  27. {
  28. size_t found = name.find_last_of("/\\");
  29. return name.substr(0, found);
  30. }
  31. std::string CFileInfo::getExtension() const
  32. {
  33. // Get position of file extension dot
  34. size_t dotPos = name.find_last_of('.');
  35. if(dotPos != std::string::npos)
  36. return name.substr(dotPos);
  37. return "";
  38. }
  39. std::string CFileInfo::getFilename() const
  40. {
  41. const size_t found = name.find_last_of("/\\");
  42. return name.substr(found + 1);
  43. }
  44. std::string CFileInfo::getStem() const
  45. {
  46. std::string rslt = name;
  47. // Remove file extension
  48. const size_t dotPos = name.find_last_of('.');
  49. if(dotPos != std::string::npos)
  50. rslt.erase(dotPos);
  51. return rslt;
  52. }
  53. std::string CFileInfo::getBaseName() const
  54. {
  55. size_t begin = name.find_last_of("/\\");
  56. size_t end = name.find_last_of(".");
  57. if(begin == std::string::npos)
  58. begin = 0;
  59. else
  60. ++begin;
  61. if (end < begin)
  62. end = std::string::npos;
  63. size_t len = (end == std::string::npos ? std::string::npos : end - begin);
  64. return name.substr(begin, len);
  65. }
  66. EResType::Type CFileInfo::getType() const
  67. {
  68. return EResTypeHelper::getTypeFromExtension(getExtension());
  69. }
  70. std::time_t CFileInfo::getDate() const
  71. {
  72. return boost::filesystem::last_write_time(name);
  73. }