1. 程式人生 > >Qt遞迴查詢所有指定字尾名的檔案

Qt遞迴查詢所有指定字尾名的檔案

// input: findPath: 指定資料夾 
//	  format: 指定格式
//	  receiveFilePath: 儲存所有指定字尾名檔案的路徑(絕對路徑+檔名)
bool MainWindow::GetAllAVIFilePath(QString &findPath, QString format = "*.text", \
				QList<QString>& receiveFilePath)
{
    QDir *dir = new QDir(findPath);
    if(!dir->exists())
        return false;
QStringList filter; filter << format; QList<QFileInfo> *dirInfoList = new QList<QFileInfo>(dir->entryInfoList(QDir::Dirs)); QList<QFileInfo> *fomatInfoList = new QList<QFileInfo>(dir->entryInfoList(filter)); for (int i = 0; i < dirInfoList->
count(); i++) { if(dirInfoList->at(i).fileName() == "." || dirInfoList->at(i).fileName() == "..") continue; QString dirTmp = dirInfoList->at(i).filePath(); GetAllAVIFilePath(dirTmp, format, receiveFilePath); } for (int i = 0; i < fomatInfoList->
count(); i++) { receiveFilePath << fomatInfoList->at(i).filePath(); } delete dirInfoList; delete dir; return true; }