Results 1 to 2 of 2

Thread: Fast solution to list directories recursively

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Fast solution to list directories recursively

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

    Qt Code:
    1. QDirIterator directories(dir_, QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
    2. while(directories.hasNext()){
    3. directories.next();
    4. dirs.push_back(directories.filePath());
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //codes base on BFS(breadth first search)
    2. QStringList scan_dir_recursive(QDir const &dir)
    3. {
    4. std::queue<QString> queue;
    5. queue.push(dir.absolutePath());
    6. QStringList results;
    7. while (!queue.empty()) {
    8. auto const subdir_name = queue.front();
    9. queue.pop();
    10. results.push_back(subdir_name);
    11. QDir subdir(subdir_name);
    12.  
    13. auto const &directories = subdir.entryInfoList({},
    14. QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    15. for (auto const &data : directories) {
    16. queue.push(data.absoluteFilePath());
    17. }
    18. }
    19.  
    20. return results;
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by stereoMatching; 2nd February 2014 at 15:32.

  2. #2
    Join Date
    Jul 2014
    Posts
    32
    Qt products
    Qt5
    Platforms
    Windows

    Default 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:

    Qt Code:
    1. StringList files;
    2. QDirIterator it(source , QDir::Files , QDirIterator::Subdirectories); //QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot
    3.  
    4. while (it.hasNext())
    5. {
    6.  
    7. files.append(it.next());
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Cound not find or load qt platform plugin windows... No working solution yet !
    By bouchebeu in forum Installation and Deployment
    Replies: 1
    Last Post: 28th October 2013, 00:52
  2. Replies: 0
    Last Post: 23rd November 2011, 15:14
  3. Return number of directories in a directories
    By franco.amato in forum Newbie
    Replies: 7
    Last Post: 29th September 2010, 23:29
  4. Fast Clipping [SOLUTION]
    By maverick_pol in forum Qt Programming
    Replies: 14
    Last Post: 24th October 2008, 12:30
  5. Recursively changing margins/padding
    By ghorwin in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2007, 11:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.