com.trolltech.qt.core
Class QDirIterator

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.core.QDirIterator
All Implemented Interfaces:
QtJambiInterface

public class QDirIterator
extends QtJambiObject

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 = new QDirIterator("/etc",
            new QDirIterator.IteratorFlags(QDirIterator.IteratorFlag.Subdirectories));
        while (it.hasNext()) {
            System.out.println(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.


Nested Class Summary
static class QDirIterator.IteratorFlag
          This enum describes flags that you can combine to configure the behavior of QDirIterator.
static class QDirIterator.IteratorFlags
           
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QDirIterator(QDir dir)
          Constructs a QDirIterator that can iterate over dir's entrylist, using dir's name filters and regular filters.
QDirIterator(QDir dir, QDirIterator.IteratorFlag[] flags)
          This is an overloaded method provided for convenience.
QDirIterator(QDir dir, QDirIterator.IteratorFlags flags)
          Constructs a QDirIterator that can iterate over dir's entrylist, using dir's name filters and regular filters.
QDirIterator(java.lang.String path)
          Constructs a QDirIterator that can iterate over path.
QDirIterator(java.lang.String path, java.util.List nameFilters)
          Constructs a QDirIterator that can iterate over path, using nameFilters and filters.
QDirIterator(java.lang.String path, java.util.List nameFilters, QDir.Filters filters)
          Constructs a QDirIterator that can iterate over path, using nameFilters and filters.
QDirIterator(java.lang.String path, java.util.List nameFilters, QDir.Filters filters, QDirIterator.IteratorFlag[] flags)
          This is an overloaded method provided for convenience.
QDirIterator(java.lang.String path, java.util.List nameFilters, QDir.Filters filters, QDirIterator.IteratorFlags flags)
          Constructs a QDirIterator that can iterate over path, using nameFilters and filters.
QDirIterator(java.lang.String path, QDir.Filters filter)
          Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering.
QDirIterator(java.lang.String path, QDir.Filters filter, QDirIterator.IteratorFlag[] flags)
          This is an overloaded method provided for convenience.
QDirIterator(java.lang.String path, QDir.Filters filter, QDirIterator.IteratorFlags flags)
          Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering.
QDirIterator(java.lang.String path, QDirIterator.IteratorFlag[] flags)
          This is an overloaded method provided for convenience.
QDirIterator(java.lang.String path, QDirIterator.IteratorFlags flags)
          Constructs a QDirIterator that can iterate over path.
 
Method Summary
 QFileInfo fileInfo()
          Returns a QFileInfo for the current directory entry.
 java.lang.String fileName()
          Returns the file name for the current directory entry, without the path prepended.
 java.lang.String filePath()
          Returns the full file path for the current directory entry.
 boolean hasNext()
          Returns true if there is at least one more entry in the directory; otherwise, false is returned.
 java.lang.String next()
          Advances the iterator to the next entry, and returns the file path of this new entry.
 java.lang.String path()
          Returns the base directory of the iterator.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QDirIterator

public QDirIterator(QDir dir,
                    QDirIterator.IteratorFlag[] flags)
This is an overloaded method provided for convenience.


QDirIterator

public QDirIterator(QDir dir)
Constructs a QDirIterator that can iterate over dir's entrylist, using dir's name filters and regular filters. You can pass options via flags to decide 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.

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(QDir dir,
                    QDirIterator.IteratorFlags flags)
Constructs a QDirIterator that can iterate over dir's entrylist, using dir's name filters and regular filters. You can pass options via flags to decide 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.

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(java.lang.String path,
                    QDir.Filters filter,
                    QDirIterator.IteratorFlag[] flags)
This is an overloaded method provided for convenience.


QDirIterator

public QDirIterator(java.lang.String path,
                    QDir.Filters filter)
Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. You can pass options via flags to decide how the directory should be iterated.

By default, filters is QDir::NoFilter , and flags is NoIteratorFlags , which provides the same behavior as in QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

Warning: This constructor expects flags to be left at its default value. Use the constructors that do not take the filters argument instead.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(java.lang.String path,
                    QDir.Filters filter,
                    QDirIterator.IteratorFlags flags)
Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. You can pass options via flags to decide how the directory should be iterated.

By default, filters is QDir::NoFilter , and flags is NoIteratorFlags , which provides the same behavior as in QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

Warning: This constructor expects flags to be left at its default value. Use the constructors that do not take the filters argument instead.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(java.lang.String path,
                    QDirIterator.IteratorFlag[] flags)
This is an overloaded method provided for convenience.


QDirIterator

public QDirIterator(java.lang.String path)
Constructs a QDirIterator that can iterate over path. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags , which provides the same behavior as in QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(java.lang.String path,
                    QDirIterator.IteratorFlags flags)
Constructs a QDirIterator that can iterate over path. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags , which provides the same behavior as in QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(java.lang.String path,
                    java.util.List nameFilters,
                    QDir.Filters filters,
                    QDirIterator.IteratorFlag[] flags)
This is an overloaded method provided for convenience.


QDirIterator

public QDirIterator(java.lang.String path,
                    java.util.List nameFilters,
                    QDir.Filters filters)
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags , which provides the same behavior as QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

Warning: This constructor expects flags to be left at its default value. Use the constructors that do not take the filters argument instead.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(java.lang.String path,
                    java.util.List nameFilters)
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags , which provides the same behavior as QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

Warning: This constructor expects flags to be left at its default value. Use the constructors that do not take the filters argument instead.

See also:
hasNext(), next(), and IteratorFlags.


QDirIterator

public QDirIterator(java.lang.String path,
                    java.util.List nameFilters,
                    QDir.Filters filters,
                    QDirIterator.IteratorFlags flags)
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags , which provides the same behavior as QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

Warning: This constructor expects flags to be left at its default value. Use the constructors that do not take the filters argument instead.

See also:
hasNext(), next(), and IteratorFlags.

Method Detail

fileInfo

public final QFileInfo fileInfo()
Returns a QFileInfo for the current directory entry. If the current entry is invalid (i.e., isValid() returns false), a null QFileInfo is returned.

See also:
filePath(), and fileName().


fileName

public final java.lang.String fileName()
Returns the file name for the current directory entry, without the path prepended. If the current entry is invalid (i.e., isValid() returns false), a null QString is returned.

This function is provided for the convenience when iterating single directories. For recursive iteration, you should call filePath() or fileInfo() instead.

See also:
filePath(), and fileInfo().


filePath

public final java.lang.String filePath()
Returns the full file path for the current directory entry. If the current entry is invalid (i.e., isValid() returns false), a null QString is returned.

See also:
fileInfo(), and fileName().


hasNext

public final boolean hasNext()
Returns true if there is at least one more entry in the directory; otherwise, false is returned.

See also:
next(), fileName(), filePath(), and fileInfo().


next

public final java.lang.String 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.

See also:
hasNext(), fileName(), filePath(), and fileInfo().


path

public final java.lang.String path()
Returns the base directory of the iterator.