|  | Home · Overviews · Examples

# QDirIterator Class Reference
[com.trolltech.qt.core module]

The `QDirIterator` class provides an iterator for directory entrylists. More...

## Detailed Description

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. Here's how to iterate over all the entries sequentially:

        QDirIterator it("/etc", QDirIterator::Subdirectories);
        while (it.hasNext()) {
            qDebug() << it.next();

            // /etc/.
            // /etc/..
            // /etc/X11
            // /etc/X11/fs
            // ...
        }

The `next` function 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` function returns only the name of the file, similar to how QDir::entryList() works. You can also call `fileInfo` to get a `QFileInfo` for the current entry.

Unlike Qt's container iterators, `QDirIterator` is uni-directional (i.e., you cannot iterate directories in reverse order) and does not allow random access.

`QDirIterator` works with all supported file engines, and is implemented using `QAbstractFileEngineIterator`.

See also `QDir`, `QDir::entryList`, and `QAbstractFileEngineIterator`.