31 lines
706 B
C++
31 lines
706 B
C++
#include "traverse_bfs.h"
|
|
|
|
Traverse_BFS::Traverse_BFS(const QString& path)
|
|
{
|
|
Q_ASSERT('/' == path.at(0));
|
|
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;
|
|
}
|