C++ (Qt)void FindFiles::find2(QString pathr, QStringList filters){ qint64 start; qint64 stop; start = QDateTime::currentMSecsSinceEpoch(); QVector<QRegExp> regFilters; regFilters.reserve(filters.size()); if (!filters.isEmpty() && !filters.contains("*")) { for (qint32 i=0; i<filters.count(); i++) { QRegExp regFilter(filters.at(i), Qt::CaseInsensitive, QRegExp::Wildcard); regFilter.setMinimal(true); regFilters.append(regFilter); } } QStack<QString> dirs; QString path; QStringList *listFiles = new QStringList; if(pathr.isEmpty()) path = QDir::currentPath(); else path = pathr; dirs.push(path); while (!dirs.isEmpty()) { path = dirs.pop(); QDir dir(path); if(!dir.exists()) continue; foreach (QFileInfo file, dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) { if(file.isDir()) { dirs.push(file.absoluteFilePath()); } else { if (regFilters.isEmpty()) { *listFiles << file.absoluteFilePath(); } else { for (qint32 i=0; i<regFilters.count(); i++) { if (regFilters.at(i).exactMatch(file.fileName())) { *listFiles << file.absoluteFilePath(); break; } } } } } } stop = QDateTime::currentMSecsSinceEpoch(); emit finded2(listFiles, stop-start);}
C++ (Qt)foreach (QString file, dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) { if(m_stop) return listFiles; QFileInfo temp(dir,file); if(temp.isDir()) dirs.push(path + QDir::separator() + file); else if(m_FilterNames.contains("*." + temp.suffix(), Qt::CaseInsensitive)) { listFiles << QFileInfo(dir, file).absoluteFilePath(); m_countFiles++; emit currentCountFiles(m_countFiles); } }