Qtc++. Improve file search in directory and subdirectories


There is a code:

 // Получение списка файлов в папке
    QStringList nameFilter;
        QDir dir(MTEPathTMP);
        nameFilter << "*.png";

        QFileInfoList list = dir.entryInfoList( nameFilter, QDir::Files );
        QFileInfo fileinfo;

        foreach (fileinfo, list) nameFilter << fileinfo.absoluteFilePath();

It searches for files by mask in a directory.

BUT! It does not know how to look in subdirectories. How can I modify it so that it can search?


Already discussed here . I would recommend not to reinvent the wheel with a recursive function, but to use the ready-made QDirIterator class with a special flag in the parameters.

QDirIterator it("/sys", QStringList() << "scaling_cur_freq", QDir::NoFilter, QDirIterator::Subdirectories);
while (it.hasNext()) {
    QFile f(it.next());
    qDebug() << f.fileName() << f.readAll().trimmed().toDouble() / 1000 << "MHz";
Scroll to Top