Qt实现遍历文件夹和文件目录(递归)

bool FindFile(const QString & path)
{
    QDir dir(path);
     if (!dir.exists())
     return false;
     dir.setFilter(QDir::Dirs|QDir::Files);
     dir.setSorting(QDir::DirsFirst);
     QFileInfoList list = dir.entryInfoList();
     int i=0;
      do{

                       QFileInfo fileInfo = list.at(i);
                       if(fileInfo.fileName()=="."|fileInfo.fileName()=="..")
                       {
                               i++;
                               continue;
                       }
                       bool bisDir=fileInfo.isDir();
                       if(bisDir)
                       {
                           nFiles++;
                           std::cout << qPrintable(QString("%1 %2 %3").arg(fileInfo.size(), 10)
                                                                   .arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<endl;

                             FindFile(fileInfo.filePath());
                       }
                       else{
                           nFiles++;
                           std::cout << qPrintable(QString("%1 %2 %3").arg(fileInfo.size(), 10)
                                                                   .arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<endl;
                   }
                      i++;
            }while(i<list.size());
      return true;
}

你可能感兴趣的:(list,qt,Path)