遍历一个目录下所有文件
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;
}
}
}
大神,如果给些注释就完美了,对于基础差的看的有点累呀
页:
[1]