ukui-search/libsearch/index/traverse_bfs.cpp

31 lines
706 B
C++
Raw Normal View History

2020-12-30 15:31:36 +08:00
#include "traverse_bfs.h"
Traverse_BFS::Traverse_BFS(const QString& path)
{
Q_ASSERT('/' == path.at(0));
2020-12-30 15:31:36 +08:00
this->path = path;
}
void Traverse_BFS::Traverse(){
QQueue<QString> bfs;
bfs.enqueue(this->path);
QFileInfoList list;
QDir dir;
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
dir.setSorting(QDir::DirsFirst);
while (!bfs.empty()) {
dir.setPath(bfs.dequeue());
list = dir.entryInfoList();
for (auto i : list){
if (i.isDir()){
bfs.enqueue(i.absoluteFilePath());
}
DoSomething(i);
}
}
}
void Traverse_BFS::setPath(const QString& path){
this->path = path;
}