递归迭代一个目录中的所有文件及其在Qt中的子目录 [英] Recursively iterate over all the files in a directory and its subdirectories in Qt

查看:601
本文介绍了递归迭代一个目录中的所有文件及其在Qt中的子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想递归地扫描一个目录及其所有子目录中具有给定扩展名的文件,例如,所有* .jpg文件。

I want to recursively scan a directory and all its sub-directories for files with a given extension - for example, all *.jpg files. How can you do that in Qt?

推荐答案

我建议你看看 QDirIterator

QDirIterator it(dir, QStringList() << "*.jpg", QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext())
    qDebug() << it.next();

这使得算法更具可扩展性。 当许多文件存储在单个目录中时,QDir :: entryList()可能会突然占用大量内存。不适合小型嵌入式设备。

This makes the algorithm more scalable. QDir::entryList() might take suddenly large amount of memory when many files are stored in a single directory. Not good on small embedded devices.

这篇关于递归迭代一个目录中的所有文件及其在Qt中的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆