• PySide 模块
  • PySide.QtCore
  • 内容表

    上一话题

    QDir

    下一话题

    QFileInfo

    QDirIterator

    概要

    函数

    详细描述

    PySide.QtCore.QDirIterator class provides an iterator for directory entrylists.

    可以使用 PySide.QtCore.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() , PySide.QtCore.QDirIterator does not support sorting.

    PySide.QtCore.QDirIterator constructor takes a PySide.QtCore.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:

    it = QDirIterator("/etc", QDirIterator.Subdirectories)
    while it.hasNext():
        print it.next()
        # /etc/.
        # /etc/..
        # /etc/X11
        # /etc/X11/fs
        # ...
    										

    PySide.QtCore.QDirIterator.next() function returns the path to the next directory entry and advances the iterator. You can also call PySide.QtCore.QDirIterator.filePath() to get the current file path without advancing the iterator. The PySide.QtCore.QDirIterator.fileName() function returns only the name of the file, similar to how QDir.entryList() works. You can also call PySide.QtCore.QDirIterator.fileInfo() to get a PySide.QtCore.QFileInfo for the current entry.

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

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

    class PySide.QtCore. QDirIterator ( dir [ , flags=QDirIterator.NoIteratorFlags ] )
    class PySide.QtCore. QDirIterator ( path , filter [ , flags=QDirIterator.NoIteratorFlags ] )
    class PySide.QtCore. QDirIterator ( path [ , flags=QDirIterator.NoIteratorFlags ] )
    class PySide.QtCore. QDirIterator ( path , nameFilters [ , filters=QDir.NoFilter [ , flags=QDirIterator.NoIteratorFlags ] ] )
    参数:
    • flags PySide.QtCore.QDirIterator.IteratorFlags
    • dir PySide.QtCore.QDir
    • path – unicode
    • filter PySide.QtCore.QDir.Filters
    • nameFilters – list of strings
    • filters PySide.QtCore.QDir.Filters
    PySide.QtCore.QDirIterator. IteratorFlag

    This enum describes flags that you can combine to configure the behavior of PySide.QtCore.QDirIterator .

    常量 描述
    QDirIterator.NoIteratorFlags The default value, representing no flags. The iterator will return entries for the assigned path.
    QDirIterator.Subdirectories List entries inside all subdirectories as well.
    QDirIterator.FollowSymlinks When combined with Subdirectories, this flag enables iterating through all subdirectories of the assigned path, following all symbolic links. Symbolic link loops (e.g., “link” => ”.” or “link” => ”..”) are automatically detected and ignored.
    PySide.QtCore.QDirIterator. fileInfo ( )
    返回类型: PySide.QtCore.QFileInfo

    返回 PySide.QtCore.QFileInfo for the current directory entry.

    PySide.QtCore.QDirIterator. fileName ( )
    返回类型: unicode

    Returns the file name for the current directory entry, without the path prepended.

    This function is convenient when iterating a single directory. When using the QDirIterator.Subdirectories flag, you can use PySide.QtCore.QDirIterator.filePath() to get the full path.

    PySide.QtCore.QDirIterator. filePath ( )
    返回类型: unicode

    Returns the full file path for the current directory entry.

    PySide.QtCore.QDirIterator. hasNext ( )
    返回类型: PySide.QtCore.bool

    Returns true if there is at least one more entry in the directory; otherwise, false is returned.

    PySide.QtCore.QDirIterator. next ( )
    返回类型: unicode

    Advances the iterator to the next entry, and returns the file path of this new entry. If PySide.QtCore.QDirIterator.hasNext() returns false, this function does nothing, and returns a null PySide.QtCore.QString .

    可以调用 PySide.QtCore.QDirIterator.fileName() or PySide.QtCore.QDirIterator.filePath() to get the current entry file name or path, or PySide.QtCore.QDirIterator.fileInfo() to get a PySide.QtCore.QFileInfo for the current entry.

    PySide.QtCore.QDirIterator. path ( )
    返回类型: unicode

    Returns the base directory of the iterator.