57 std::ostringstream ss ;
58 static int sequence = 1 ;
65 return 0 == usable( for_creation ) ;
78 list.m_list.swap( out ) ;
84 readType( dir , {} ) ;
85 return m_list.size() ;
90 readImp( dir ,
true , {} , limit ) ;
91 return m_list.size() ;
96 readImp( dir ,
false , suffix , limit ) ;
97 return m_list.size() ;
100void G::DirectoryList::readImp(
const G::Path & dir ,
bool sub_dirs , std::string_view suffix ,
unsigned int limit )
104 while( iter.more() && !iter.error() )
106 if( sub_dirs ? iter.isDir() : ( suffix.empty() ||
Str::tailMatch(iter.fileName(),suffix) ) )
108 if( limit == 0U || m_list.size() < limit )
111 item.m_is_dir = iter.isDir() ;
112 item.m_is_link = iter.isLink() ;
113 item.m_path = iter.filePath() ;
114 item.m_name = iter.fileName() ;
115 m_list.insert( std::lower_bound(m_list.begin(),m_list.end(),item) , item ) ;
117 if( m_list.size() == limit )
126 return m_list.empty() ;
136 more = ! m_list.empty() ;
141 more = m_index < m_list.size() ;
149 return m_list.at(m_index).m_is_link ;
155 return m_list.at(m_index).m_is_dir ;
160 return m_list.at(m_index).m_path ;
165 return m_list.at(m_index).m_name ;
A iterator that returns unsorted filenames in a directory.
A iterator similar to G::DirectoryIterator but doing all file i/o in one go and providing a sorted re...
bool isLink() const
Returns true if the current item is a symlink.
Path filePath() const
Returns the current path.
std::size_t readAll(const Path &dir)
An initialiser that is to be used after default construction.
bool empty() const noexcept
Returns true if empty.
bool more()
Returns true if more and advances by one.
std::string fileName() const
Returns the current filename.
std::size_t readType(const Path &dir, std::string_view suffix, unsigned int limit=0U)
An initialiser that is to be used after default construction.
std::size_t readDirectories(const Path &dir, unsigned int limit=0U)
An initialiser that reads all sub-directories.
DirectoryList()
Default constructor for an empty list.
bool isDir() const
Returns true if the current item is a directory.
An encapsulation of a file system directory that works with G::DirectoryIterator.
static std::string tmp()
A convenience function for constructing a filename for writeable().
Path path() const
Returns the directory's path, as passed in to the ctor.
bool valid(bool for_creating_files=false) const
Returns true iff usable() is zero.
Directory()
Default constructor for the current directory.
A Path object represents a file system path.
static bool tailMatch(std::string_view in, std::string_view ending) noexcept
Returns true if the string has the given ending (or the given ending is empty).
static SystemTime now()
Factory function for the current time.