Analog os.walk in PyQt

Before I can continue implementing the dir / file recursive search with some filtering for some tasks, I want to know if Qt / PyQt has an analogue os.walk.

Main application - a graphical application in PyQt4, and all text fields in objects QStringand paths (files, directories) are used QFile, QDir, QFileinfofor manipulation.

By analogy, I mean the fast and convenient recursive tool to traverse the fs tree.

Should I use os.walkor something much faster and more informative?

PS. Maybe this one can help me, but I'm not sure if this is more effective than that os.walk.

+3
source share
1

os.walk - ?

, os.walk python, . , .

, Qt , QDir, , , os.walk.

Qt, , .

main.cpp

#include <QDir>
#include <QFileInfoList>
#include <QDebug>

void traverse( const QString& dirname )
{
    QDir dir(dirname);
    dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoSymLinks | QDir::NoDot | QDir::NoDotDot);

    foreach (QFileInfo fileInfo, dir.entryInfoList()) {
      if (fileInfo.isDir() && fileInfo.isReadable())
          traverse(fileInfo.absoluteFilePath());
      else
          qDebug() << fileInfo.absoluteFilePath();
    }
}

int main()
{
    traverse("/usr/lib");
    return 0;
}

, :

#include <QDirIterator>
#include <QDebug>

int main()
{
    QDirIterator it("/etc", QDirIterator::Subdirectories);
    while (it.hasNext())
        qDebug() << it.next();
    return 0;
}

main.pro

TEMPLATE = app
TARGET = qdir-traverse
QT = core
SOURCES += main.cpp

qmake && make && ./qdir-traverse

. , .

+3

All Articles