Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    2
    3
    1211
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      MrNoway last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • K
        KA51O last edited by

        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 .

        1 Reply Last reply Reply Quote 0
        • M
          MrNoway last edited by

          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;
          

          }@

          1 Reply Last reply Reply Quote 0
          • First post
            Last post