Important: Please read the Qt Code of Conduct -

file search with regexp

  • I'm looking for a way to find all files in a directory with a particular extension. For example, all .txt files within the download folder.

    This seems straightforward, and I thought I could do it with QStandardPaths::locateAll(QStandardPaths::DownloadLocation, "*.txt") but that doesn't work.

    However, if I do QStandardPaths::locateAll(QStandardPaths::DownloadLocation, "somefile.txt") then it will return a QStringList with "somefile.txt" in it. So I think I'm close. I figured I might be able to use QRegularExpression here, but it's not clear to me how I would do that. Any suggestions?

  • Lifetime Qt Champion

    @kgregory said in file search with regexp:


    This is not what you need.

    QDir dir("YOUR SEARCH PATH");
    qDebug() << dir.entryList(QStringList() << "*.txt", QDir::Files);

Log in to reply