2

As I have to process a large number of files, I'd like to show a progress of this process.

I know that iterating using QDirIterator::next() is the best option, but first I need to know the total number of files in a directory (and all its subdirectories).

What is the fastest method to count a large set of files?

paws
  • 197
  • 1
  • 2
  • 13
  • Possible duplicate of [Counting file in a directory](http://stackoverflow.com/questions/6890757/counting-file-in-a-directory) – demonplus Sep 02 '16 at 07:31

1 Answers1

2

Use below code to count all files and directories inside "opt" folder

QDir dir("/opt/");
dir.count();

Use below code to list *.jpg files in current and all its subdirectories.

QDirIterator it("/opt/", QStringList() << "*.jpg", QDir::Files, QDirIterator::Subdirectories);
int count = 0;
while (it.hasNext()){
    qDebug() << it.next();
    count++;
}
qDebug() << "count:" << count;
Amol
  • 56
  • 1
  • 7
  • Thx. But I didn't mention one detail: I need to count only files with given extention... For example count all *.jpg in directory and its all subdirectories. – paws Sep 05 '16 at 12:41
  • I hoped that there is faster method to find the number of files with given extension, however thank you a lot for your time! – paws Sep 12 '16 at 09:34