QT 遍历目录查找指定文件(比较简单)

时间:2020-12-04 12:41:19

QString FindFile(const QString &strFilePath, const QString &strNameFilters)
{
 if (strFilePath.isEmpty() || strNameFilters.isEmpty())
 {
  return QString();
 }

 QDir dir;
    QStringList filters;

    filters << strNameFilters;
    dir.setPath(strFilePath);
    dir.setNameFilters(filters);
    QDirIterator iter(dir,QDirIterator::Subdirectories);

    while (iter.hasNext())
    {
        iter.next();
        QFileInfo info=iter.fileInfo();
        if (info.isFile())
  {
   return info.absoluteFilePath().replace('/', '\\');
        }
    }

 return QString();
}

http://blog.csdn.net/itjobtxq/article/details/8350985