Fast solution to list directories recursively



  • Do you know a faster solution to find all of the directories by Qt(QDirIterator is too slow)

    @
    QDirIterator directories(dir_, QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
    QStringList dirs;
    while(directories.hasNext()){
    directories.next();
    dirs.push_back(directories.filePath());
    }
    @

    @ //codes base on BFS(breadth first search)
    QStringList scan_dir_recursive(QDir const &dir)
    {
    std::queue<QString> queue;
    queue.push(dir.absolutePath());
    QStringList results;
    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({},
        QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
        for (auto const &data : directories) {
          queue.push(data.absoluteFilePath());
        }
    }
     
      return results;
    }@


  • If QDirIterator is too slow, then perhaps your file system is too slow.



  • [quote author="Andre" date="1391353747"]If QDirIterator is too slow, then perhaps your file system is too slow.[/quote]
    In other words, QDirIterator is already very fast?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.