Fast solution to list directories recursively
Do you know a faster solution to find all of the directories by Qt(QDirIterator is too slow)
Code:
QDirIterator directories
(dir_,
QDir::Dirs |
QDir::NoSymLinks |
QDir::NoDotAndDotDot, QDirIterator
::Subdirectories);
while(directories.hasNext()){
directories.next();
dirs.push_back(directories.filePath());
}
Code:
//codes base on BFS(breadth first search)
{
std::queue<QString> queue;
queue.push(dir.absolutePath());
while (!queue.empty()) {
auto const subdir_name = queue.front();
queue.pop();
results.push_back(subdir_name);
QDir subdir
(subdir_name
);
auto const &directories = subdir.entryInfoList({},
for (auto const &data : directories) {
queue.push(data.absoluteFilePath());
}
}
return results;
}
Re: Fast solution to list directories recursively
I dont know where to post, so I just use your post.
I found out that "QDir::NoSymLinks" is very slow. I compared it with the windows dir command. Now both methods runs in a similar speed. Both needed 3 seconds to run through the QT folder. 33000 files in 1100 folders.
With QDir::NoSymLinks on, it took 11 seconds.
I have to run my tool on a network and it is around 100 times slower than the dir command method.
my used code is quite simple:
Code:
StringList files;
QDirIterator it
(source ,
QDir::Files , QDirIterator
::Subdirectories);
//QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot
while (it.hasNext())
{
files.append(it.next());
}