CFileInfo.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 && name[dotPos] == '.')
  36. return name.substr(dotPos);
  37. else
  38. return "";
  39. }
  40. std::string CFileInfo::getFilename() const
  41. {
  42. size_t found = name.find_last_of("/\\");
  43. return name.substr(found + 1);
  44. }
  45. std::string CFileInfo::getStem() const
  46. {
  47. std::string rslt = name;
  48. // Remove file extension
  49. size_t dotPos = name.find_last_of("/.");
  50. if(dotPos != std::string::npos && name[dotPos] == '.')
  51. rslt.erase(dotPos);
  52. return rslt;
  53. }
  54. std::string CFileInfo::getBaseName() const
  55. {
  56. size_t begin = name.find_last_of("/");
  57. size_t end = name.find_last_of("/.");
  58. if(end != std::string::npos && name[end] == '/')
  59. end = std::string::npos;
  60. if(begin == std::string::npos)
  61. begin = 0;
  62. else
  63. begin++;
  64. return name.substr(begin, end - begin);
  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. }