Results 1 to 3 of 3

Thread: [QT4] Counting files in a directory (Linux)

  1. #1
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default [QT4] Counting files in a directory (Linux)

    First the relevant background: I have a spool directory that I need to get the total number of files in. I don't care about the contents, just how many files. Here's the catch: it's a big number. In this case 1,000,000 files. (Yes it should be hashed but that is not currently an option.)

    So, I've tried QProcess with find or ls. They work. I've also tried QDir and it's count() method. It works.

    So what's the problem? It's friggin slow. For comparison if I run find manually, piping to "wc -l", it is a lot faster. Doing it by hand takes from 1/4 to 1/2 the time that doing it in Qt using QProcess, and even less than QDir::count() - count takes a few minutes.

    So any idea as to which *should* be the fastest route? Why does QDir::count() take *so* long (~4-5 minutes)?
    --
    The Real Bill

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QT4] Counting files in a directory (Linux)

    Because it first builds a list of the files and then sorts the list .
    Qt Code:
    1. ...
    2. uint QDir::count() const
    3. {
    4. Q_D(const QDir);
    5.  
    6. d->updateFileLists();
    7. return d->data->files.count();
    8. }
    9. ...
    10. inline void QDirPrivate::updateFileLists() const
    11. {
    12. if(data->listsDirty) {
    13. QStringList l = data->fileEngine->entryList(data->filters, data->nameFilters);
    14. sortFileList(data->sort, l, &data->files, &data->fileInfos);
    15. data->listsDirty = 0;
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    So, I think you should use platform API, and just count the files, no backstore, or anything similar.

    Regards

  3. The following user says thank you to marcel for this useful post:

    ucntcme (24th July 2007)

  4. #3
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: [QT4] Counting files in a directory (Linux)

    So that explains QDire::count()'s slowness, thanks. That's a mite bit painful though.

    But why does QProcess executing find take so much longer than the same command in the shell "manually"? I'd expect a small bit of overhead, but a difference of double or more is a bit unexpected, particularly when the difference is over 30 seconds.

    Ah well.
    Thanks again.
    --
    The Real Bill

Similar Threads

  1. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.