Important: Please read the Qt Code of Conduct -

[SOLVED] Read unknown .txt files in a folder?

  • let's say there are some unknown .txt files in a folder,

    how can I read them without knowing the file names?

    is that possible, I googled already quite alot, but couldnt find anything

    € so how can I request the file names? If I know them I can also read them.

  • If you know the filepath for the folder where the files are stored you can get the individual file in the directory using "QDir": . Have a look at the "examples": , its pretty much selfexplanatory.

    To open the files you can use "QFile": .

  • cool thx,

    luckily there was an already nice sample code

    this could be helpful for someone, nice

    @ QFile file2("movie-list.txt"); | QIODevice::Text);
    QTextStream out2(&file2);

     QDir dir("movies");
     dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
     dir.setSorting(QDir::Size | QDir::Reversed);
     QFileInfoList list = dir.entryInfoList();
     out2 << "     Bytes Filename" << endl;
     for (int i = 0; i < list.size(); ++i) {
         QFileInfo fileInfo =;
        out2 << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
                                                 .arg(fileInfo.fileName())) << endl;


Log in to reply