View Full Version : Searching files from directories & its subdirectories

27th October 2007, 09:02
Hi All,

I am trying to search files from directories & its subdirectories. I want to do recursive searching. I am unable to find option to do it.
Please tell me the way to do recursive searching using QFileDialog.

Thanks in advance!

27th October 2007, 12:17
You have to get the entries of a directory and then iterate over every single file and check whether it is a directory itself. If that is true, you recursively start the function on that file. Take a look at the entryList() and entryInfoList() members of QDir.

27th October 2007, 12:51
See this post for how to recursively iterate through a directory and its subdirectories: http://www.qtcentre.org/forum/p-recursive-removal-of-dirs-post45687/postcount2.html. Alternatively, you could abuse QDirModel and QAbstractItemModel::match().

27th October 2007, 12:59
ugly implementation to give you a little bit of a hint on how to do it.

#include <QApplication>
#include <QtGui>

void listFiles(QDir, QString);

//#include "main.moc"
int main(int argc, char* argv[])
QApplication(argc, argv);
QDir dir("mydir");
listFiles(dir, "");
return 0;

void listFiles(QDir directory, QString indent)
indent += "\t";
QDir dir(directory);
QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QFileInfo finfo, list) {
qDebug() << indent + finfo.fileName() << endl;
if (finfo.isDir()) {
listFiles(QDir(finfo.absoluteFilePath()), indent);

12th April 2014, 13:57
//Show All Files On Folder And Sub-folder With extinction "*.mov"


QStringList nameFilters;

nameFilters << "*.mov";

QDirIterator dirIterator(ui->TextPath->toPlainText(),nameFilters, QDir::Files, QDirIterator::Subdirectories);
while (dirIterator.hasNext()) {