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/
Popularity: 70% [?]
Dec12












