diff --git a/FileUtils.cpp b/FileUtils.cpp index d3f09f30..bf9cfd4f 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -1,20 +1,7 @@ #include "FileUtils.h" CFile::CFile(const CString& sLongName) { - m_sLongName = sLongName; - m_iFD = -1; - - m_sShortName = sLongName; - - // @todo shouldn't this be Right() and RightChomp() ?! - while (m_sShortName.Left(1) == "/") { - m_sShortName.LeftChomp(); - } - - CString::size_type uPos = m_sShortName.rfind('/'); - if (uPos != CString::npos) { - m_sShortName = m_sShortName.substr(uPos +1); - } + SetFileName(sLongName); } CFile::~CFile() { @@ -23,6 +10,19 @@ CFile::~CFile() { } } +void CFile::SetFileName(const CString& sLongName) { + m_sLongName = sLongName; + m_iFD = -1; + + m_sShortName = sLongName; + m_sShortName.RightTrim("/"); + + CString::size_type uPos = m_sShortName.rfind('/'); + if (uPos != CString::npos) { + m_sShortName = m_sShortName.substr(uPos +1); + } +} + bool CFile::IsReg(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_REGULAR, bUseLstat); } bool CFile::IsDir(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_DIRECTORY, bUseLstat); } bool CFile::IsChr(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_CHARACTER, bUseLstat); } diff --git a/FileUtils.h b/FileUtils.h index ec70b88f..0e27674c 100644 --- a/FileUtils.h +++ b/FileUtils.h @@ -33,6 +33,7 @@ public: FT_SOCK }; + void SetFileName(const CString& sLongName); static bool IsReg(const CString& sLongName, bool bUseLstat = false); static bool IsDir(const CString& sLongName, bool bUseLstat = false); static bool IsChr(const CString& sLongName, bool bUseLstat = false);