[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":http://qt-project.org/doc/qt-4.8/qdir.html . Have a look at the "examples":http://qt-project.org/doc/qt-4.8/qdir.html#examples , its pretty much selfexplanatory.

    To open the files you can use "QFile":http://qt-project.org/doc/qt-4.8/qfile.html .



  • cool thx,

    luckily there was an already nice sample code

    this could be helpful for someone, nice

    @ QFile file2("movie-list.txt");
    file2.open(QIODevice::WriteOnly | 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 = list.at(i);
          
    
        out2 << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
                                                 .arg(fileInfo.fileName())) << endl;
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.