2
0

CFileInfo.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "StdInc.h"
  2. #include "CFileInfo.h"
  3. CFileInfo::CFileInfo() : name("")
  4. {
  5. }
  6. CFileInfo::CFileInfo(const std::string & name)
  7. : name(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. }