CopperSpice API
1.9.2
|
The QDirIterator class provides an iterator for directory entrylists. More...
Public Typedefs | |
using | IteratorFlags = QFlags< IteratorFlag > |
Public Types | |
enum | IteratorFlag |
Public Methods | |
QDirIterator (const QDir &dir, IteratorFlags flags=NoIteratorFlags) | |
QDirIterator (const QString &path, const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, IteratorFlags flags=NoIteratorFlags) | |
QDirIterator (const QString &path, IteratorFlags flags=NoIteratorFlags) | |
QDirIterator (const QString &path, QDir::Filters filters, IteratorFlags flags=NoIteratorFlags) | |
~QDirIterator () | |
QFileInfo | fileInfo () const |
QString | fileName () const |
QString | filePath () const |
bool | hasNext () const |
QString | next () |
QString | path () const |
Friends | |
class | QDir |
The QDirIterator class provides an iterator for directory entrylists.
You can use QDirIterator to navigate entries of a directory one at a time. It is similar to QDir::entryList() and QDir::entryInfoList(), but because it lists entries one at a time instead of all at once, it scales better and is more suitable for large directories. It also supports listing directory contents recursively, and following symbolic links. Unlike QDir::entryList(), QDirIterator does not support sorting.
The QDirIterator constructor takes a QDir or a directory as argument. After construction, the iterator is located before the first directory entry. The following example shows how to iterate over all the entries sequentially.
The method next() returns the path to the next directory entry and advances the iterator. You can also call filePath() to get the current file path without advancing the iterator. The fileName() method returns only the name of the file which is similar to QDir::entryList(). You can also call fileInfo() to get a QFileInfo for the current entry.
Unlike the CopperSpice container iterators, QDirIterator is uni-directional which means you can not iterate directories in reverse order and does not allow random access.
QDirIterator works with all supported file engines and is implemented using QAbstractFileEngineIterator.
Typedef for QFlags<IteratorFlag> which contains an OR combination of IteratorFlag values.
Refer to QDirIterator::IteratorFlag for the enum documentation.
This enum describes flags that you can combine to configure the behavior of QDirIterator.
Constant | Value | Description |
---|---|---|
QDirIterator::NoIteratorFlags | 0x0 | The default value, representing no flags. The iterator will return entries for the assigned path. |
QDirIterator::Subdirectories | 0x2 | List entries inside all subdirectories as well. |
QDirIterator::FollowSymlinks | 0x1 | When combined with Subdirectories this flag enables iterating through all subdirectories of the assigned path following all symbolic links. Symbolic link loops are automatically detected and ignored. |
QDirIterator::QDirIterator | ( | const QDir & | dir, |
IteratorFlags | flags = NoIteratorFlags |
||
) |
Constructs a QDirIterator which can iterate over the dir entrylist using name filters and regular filters. Pass options via flags to indicate how the directory should be iterated.
By default flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList(). The sorting in dir is ignored.
QDirIterator::QDirIterator | ( | const QString & | path, |
IteratorFlags | flags = NoIteratorFlags |
||
) |
Constructs a QDirIterator which can iterate over path. Pass options via flags to indicate how the directory should be iterated.
By default flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().
QDirIterator::QDirIterator | ( | const QString & | path, |
QDir::Filters | filters, | ||
IteratorFlags | flags = NoIteratorFlags |
||
) |
Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. Pass options via flags to indicate how the directory should be iterated.
By default filters is QDir::NoFilter, and flags is NoIteratorFlags, which provides the same behavior as QDir::entryList().
QDirIterator::QDirIterator | ( | const QString & | path, |
const QStringList & | nameFilters, | ||
QDir::Filters | filters = QDir::NoFilter , |
||
IteratorFlags | flags = NoIteratorFlags |
||
) |
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. Pass options via flags to indicate how the directory should be iterated.
By default flags is NoIteratorFlags, which provides the same behavior as QDir::entryList().
QDirIterator::~QDirIterator | ( | ) |
Destroys the QDirIterator.
QFileInfo QDirIterator::fileInfo | ( | ) | const |
Returns a QFileInfo for the current directory entry.
QString QDirIterator::fileName | ( | ) | const |
Returns the file name for the current directory entry without the path prepended. This method is convenient when iterating over a single directory. When using the QDirIterator::Subdirectories flag you can use filePath() to get the full path.
QString QDirIterator::filePath | ( | ) | const |
Returns the full file path for the current directory entry.
bool QDirIterator::hasNext | ( | ) | const |
Returns true if there is at least one more entry in the directory otherwise false is returned.
QString QDirIterator::next | ( | ) |
Advances the iterator to the next entry, and returns the file path of this new entry. If hasNext() returns false, this function does nothing, and returns a null QString.
You can call fileName() or filePath() to get the current entry file name or path, or fileInfo() to get a QFileInfo for the current entry.
QString QDirIterator::path | ( | ) | const |
Returns the base directory of the iterator.