getting all files from subdirectories recursively with c using qt framework/

// Display a dialog to the user to choose his music directory
      QString directory_path = QFileDialog::getExistingDirectory(this, tr("Select your music directory"), QDir::currentPath());
 
     // Then create an instance of our QDirIterator, which takes as parameters
     // the directory, a QDir filter and an option flag which the QDirIterator is told
     // to go on the subdirectories also.
     // I have combined the QDir filters to list files and not to get the symbolic links (shortcuts in Windows).
 
     QDirIterator directory_walker(directory_path, QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
 
    // QDirIterator object has a boolean method called hasNext() which returns true
    // if the directory have more files, false otherwise and based on that information,
    // we can write a while loop like the one below
 
    while(directory_walker.hasNext())
    {
          // then we tell our directory_walker object to explicitly take next element until the loop finishes
          directory_walker.next();
 
         // I want to list just mp3 files!
         //if(directory_walker.fileInfo().completeSuffix() == "css")
                 // then we take a filename and display it to a listWidget like the code below:
                ui->listWidget->addItem(directory_walker.fileName());
    }

Original link : phalanx.spartansoft.org/2009/01/20/getting-all-files-from-subdirectories-recursively-with-c-using-qt-framework/

Category(s): Qt, Qt-Tips

Leave a Reply

Your email address will not be published. Required fields are marked *

*

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">