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

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;
}

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>