DirIterator documentation
Allows to iterate over the entries of a directory.
For each entry, you can obtain: its name (getName()), whether the name points to a file or a directory (isDir()), and the size of the pointed file/directory (getFileSize()).
When iterating over the content of a directory, the entries are not returned in alphabetical order, nor in the order they were created (added to the directory). The order of the returned entries may appear somewhat random; this is because the directory is implemented using a hashtable.
An iterator is invalidated by a creation or removal of any entry to the underlying directory. While you're iterating over a directory, you're not allowed to use Dir::createFile(), Dir::createDir(), Dir::remove() or Dir::removeAll() on that directory, because these operations invalidate the iterator.
DirIterator(Dir underlyingDir)
Positions the iterator before the first entry of the directory.
underlyingDir is the directory on which you want to iterate.
bool moveNext()
Advances the iterator to the next entry, and indicates when the iterator is past the last entry.
The first call to moveNext() (after creating the iterator) positions the iterator on the first entry (or past-the-end, if the directory is empty).
Returns:
- true if the iterator advanced without reaching the end ( i.e. there was a next entry to advance to)
- false if the iterator was on the last entry before moveNext(), while now it's positioned past-the-end (and you can't use it anymore)
Example of iterating over all entries of a directory:
Dir myDir = storage.getRootDir();
for(DirIterator it(myDir); it.moveNext();) {
entries.push_back(it.getName());
}
const char * getName() const;
const void * getName(int *outNameLen) const;
Get the name of the current entry.
Use the first variant if you know the entry name is a NULL-terminated string (without NULLs in the middle).
Use the second variant if the name is binary data which may contain NULLs inside. In this case you explicitly obtain the length (in bytes) of the name through the parameter outNameLen
bool isDir()
Tests if the current entry represents a directory (as opposed to a file).
Returns true for a directory; false for a file.
int64 getFileSize()
Gets the size (in bytes) of the file or directory this entry points to.