hsl1990 发表于 2013-6-5 21:59:42

遍历一个目录下所有文件

void findFiles(QString rootpath)
{
    QDirModel listmodel;
    //QString rootpath = "/root/logo";
    QDir dir(rootpath);
    QStringList dirs = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs);
    if(!dirs.isEmpty())
    {
      for(int i=0; i<dirs.size(); i++)
      {
            QModelIndex index = listmodel.index(rootpath+"/"+dirs.at(i));
            QString filepath = listmodel.filePath(index);
            //qDebug() << dirs.at(i)<<filepath;
            findFiles(filepath);

      }
    }
    QStringList files = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
    if(!files.isEmpty())
    {
      for(int i=0; i < files.size(); i++)
      {
            QModelIndex index = listmodel.index(rootpath + "/" + files.at(i));
            QString filepath = listmodel.filePath(index);
            //qDebug() << "###" <<files.at(i);
            //qDebug() <<"file name..."<<filepath;
            fileList<<filepath;
      }
    }
}

cll 发表于 2014-1-10 09:58:25

大神,如果给些注释就完美了,对于基础差的看的有点累呀
页: [1]
查看完整版本: 遍历一个目录下所有文件