36 class DirectoryIteratorImp ;
51 std::string sizeString()
const ;
52 Path filePath()
const ;
53 std::string fileName()
const ;
63 struct dirent * m_dp ;
79 std::string path_dot = m_path.
str() + (m_path.
str()==
"/"?
"":
"/") +
"." ;
81 DIR * p = ::opendir( path_dot.c_str() ) ;
86 if( !error && for_creation )
89 int rc = ::access( m_path.
cstr() , W_OK ) ;
97 Path path( m_path , filename.empty() ? tmp() : filename ) ;
113 return m_imp->error() ;
118 return m_imp->more() ;
123 return m_imp->filePath() ;
128 return m_imp->fileName() ;
133 return m_imp->isDir() ;
138 return m_imp->sizeString() ;
143G::DirectoryIteratorImp::DirectoryIteratorImp(
const Directory & dir ) :
150 m_d = ::opendir( dir.
path().
cstr() ) ;
151 m_error = m_d == nullptr ;
154bool G::DirectoryIteratorImp::error()
const
159bool G::DirectoryIteratorImp::more()
163 m_dp = ::readdir( m_d ) ;
164 m_error = m_dp == nullptr ;
165 bool special = !m_error && ( fileName() ==
"." || fileName() ==
".." ) ;
166 m_is_dir = !m_error && ( special ||
File::isDirectory(filePath(),std::nothrow) ) ;
173G::Path G::DirectoryIteratorImp::filePath()
const
175 return m_dir.path() + fileName() ;
178std::string G::DirectoryIteratorImp::fileName()
const
180 return m_dp ==
nullptr ? std::string() : std::string(m_dp->d_name) ;
183bool G::DirectoryIteratorImp::isDir()
const
188G::DirectoryIteratorImp::~DirectoryIteratorImp()
194std::string G::DirectoryIteratorImp::sizeString()
const
197 return s.empty() ? std::string(
"0") : s ;
A pimple-pattern implementation class for DirectoryIterator using opendir()/readdir().
DirectoryIterator(const Directory &dir)
Constructor taking a directory reference.
std::string fileName() const
Returns the name of the current item.
bool error() const
Returns true on error. The caller should stop the iteration.
std::string sizeString() const
Returns the file size as a decimal string.
~DirectoryIterator()
Destructor.
bool isDir() const
Returns true if the current item is a directory.
bool more()
Returns true if more and advances by one.
Path filePath() const
Returns the path of the current item.
An encapsulation of a file system directory that works with G::DirectoryIterator.
int usable(bool for_creating_files=false) const
Returns zero if the object represents a valid directory with permissions that dont disallow reading o...
bool writeable(const std::string &probe_filename=tmp()) const
Tries to create and then delete an empty test file in the directory.
Path path() const
Returns the directory's path, as passed in to the ctor.
static bool probe(const char *) noexcept
Creates and deletes a temporary probe file.
static bool isDirectory(const Path &path, std::nothrow_t)
Returns true if the path exists() and is a directory.
static std::string sizeString(const Path &file)
Returns the file's size in string format.
A Path object represents a file system path.
const char * cstr() const noexcept
Returns the path string.
std::string str() const
Returns the path string.
bool empty() const noexcept
Returns true if size() is zero.
static int errno_(const SignalSafe &=G::SignalSafe()) noexcept
Returns the process's current 'errno' value.