Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Read unknown .txt files in a folder?

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views
  • 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 Offline
    M Offline
    MrNoway
    wrote on last edited by
    #1

    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
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        MrNoway
        wrote on last edited by
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved