获取目录下指定类型的所有文件
bool QtGetAllFiles(const QDir &fromDir, QStringList &fileList , const QStringList &filters) { //fromDir指定目录,fileList获取到的所有文件,filters文件过虑 QFileInfoList fileInfoList = fromDir.entryInfoList(filters, QDir::AllDirs | QDir::Files); foreach(QFileInfo fileInfo, fileInfoList) { if(fileInfo.fileName() == "." || fileInfo.fileName() == "..") continue; if(fileInfo.isDir()) { //recursion call if(!QtGetAllFiles(fileInfo.filePath(), fileList , filters)) { return false; } } else { fileList += fileInfo.absoluteFilePath(); } } return true; }
来源:https://www.cnblogs.com/jiushishuai/p/9452113.html