void countFiles() {
QString root_path("C:\\");
QTime timer;
timer.start();
std::uint64_t count = 0;
std::queue<QString> qt_dirs;
qt_dirs.push(root_path);
while (!qt_dirs.empty()) {
auto dir_path = qt_dirs.front();
qt_dirs.pop();
QDir dir(dir_path);
count += dir.entryList(QDir::Dirs | QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot).size();
for (auto &sub_dir_path : dir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot)) {
qt_dirs.push(dir.filePath(sub_dir_path));
}
}
qDebug() << Q_FUNC_INFO << "found" << count << "entries, and it took" << timer.elapsed() << "ms";
timer.start();
count = 0;
std::queue<boost::filesystem::path> dirs;
dirs.push(root_path.toStdString());
while (!dirs.empty()) {
auto dir_path = dirs.front();
dirs.pop();
try {
auto iterator_range = boost::make_iterator_range(boost::filesystem::directory_iterator(dir_path), {});
for (auto &entry : iterator_range) {
auto entry_status = entry.status();
if (boost::filesystem::is_symlink(entry_status)) continue;
if (boost::filesystem::is_directory(entry_status)) dirs.push(entry.path());
++count;
}
} catch(boost::filesystem::filesystem_error &fe) {
continue;
}
}
qDebug() << Q_FUNC_INFO << "found" << count << "entries, and it took" << timer.elapsed() << "ms";
}
Can someone explain to me, or at least give me a hint, why these 2 blocks return completely different counts of files? They both should only count directories and files, skip any symlinks. But still, on Windows this differs by around 20%
void VolumeFileTreeModel::countFiles() found 502780 entries, and it took 97549 ms
void VolumeFileTreeModel::countFiles() found 622208 entries, and it took 17022 ms