Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. how can i list the files in a directory
Forum Updated to NodeBB v4.3 + New Features

how can i list the files in a directory

Scheduled Pinned Locked Moved Unsolved Language Bindings
7 Posts 4 Posters 3.6k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    Nathan Miguel
    wrote on last edited by
    #1

    I want to list the files that are present in a directory.

    JKSHJ 1 Reply Last reply
    0
    • N Nathan Miguel

      I want to list the files that are present in a directory.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Nathan-Miguel said in how can i list the files in a directory:

      I want to list the files that are present in a directory.

      https://doc.qt.io/qt-5/qdir.html#entryList

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      N 1 Reply Last reply
      5
      • JKSHJ JKSH

        @Nathan-Miguel said in how can i list the files in a directory:

        I want to list the files that are present in a directory.

        https://doc.qt.io/qt-5/qdir.html#entryList

        N Offline
        N Offline
        Nathan Miguel
        wrote on last edited by
        #3

        @JKSH Good worked, but would somehow print this value without quotation marks and dots

        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
        
            //VAR
            QString rootDir = qApp->applicationDirPath();
            QString data = "/data";
            QDir mkDir;
            bool autostart = QDir(QDir::homePath()+"/.config/autostart").exists();
            QDir test(rootDir+data);
            QStringList testlist = test.entryList();
            QString testout = testlist.join("");
            qDebug() << testout;
        
            return 0;
        }
        

        Captura de tela de 2019-09-26 16-12-48.png

        JKSHJ jsulmJ 2 Replies Last reply
        0
        • N Nathan Miguel

          @JKSH Good worked, but would somehow print this value without quotation marks and dots

          int main(int argc, char *argv[])
          {
              QCoreApplication a(argc, argv);
          
              //VAR
              QString rootDir = qApp->applicationDirPath();
              QString data = "/data";
              QDir mkDir;
              bool autostart = QDir(QDir::homePath()+"/.config/autostart").exists();
              QDir test(rootDir+data);
              QStringList testlist = test.entryList();
              QString testout = testlist.join("");
              qDebug() << testout;
          
              return 0;
          }
          

          Captura de tela de 2019-09-26 16-12-48.png

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @Nathan-Miguel said in how can i list the files in a directory:

          print this value without quotation marks

          https://doc.qt.io/qt-5/qdebug.html#operator-lt-lt-16

          QString testout = testlist.join("");
          

          What are you trying to do with this line?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          N 1 Reply Last reply
          3
          • N Nathan Miguel

            @JKSH Good worked, but would somehow print this value without quotation marks and dots

            int main(int argc, char *argv[])
            {
                QCoreApplication a(argc, argv);
            
                //VAR
                QString rootDir = qApp->applicationDirPath();
                QString data = "/data";
                QDir mkDir;
                bool autostart = QDir(QDir::homePath()+"/.config/autostart").exists();
                QDir test(rootDir+data);
                QStringList testlist = test.entryList();
                QString testout = testlist.join("");
                qDebug() << testout;
            
                return 0;
            }
            

            Captura de tela de 2019-09-26 16-12-48.png

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Nathan-Miguel Quotation marks come from qDebug and are not part of the actual string...
            You can verify this using std::cout instead of qDebug.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            4
            • JKSHJ JKSH

              @Nathan-Miguel said in how can i list the files in a directory:

              print this value without quotation marks

              https://doc.qt.io/qt-5/qdebug.html#operator-lt-lt-16

              QString testout = testlist.join("");
              

              What are you trying to do with this line?

              N Offline
              N Offline
              Nathan Miguel
              wrote on last edited by
              #6

              @JKSH I want to basically want to set to open a file inside the folder (for example a video) automatically even if I change the name, so I need this value to be without these dots

              JonBJ 1 Reply Last reply
              0
              • N Nathan Miguel

                @JKSH I want to basically want to set to open a file inside the folder (for example a video) automatically even if I change the name, so I need this value to be without these dots

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @Nathan-Miguel
                Look, the "dots" aren't part of a file name, they are the . and the .. entries in the directory, The other two are filenames. You are choosing to print them out all touching each other (testlist.join("")). Clearly that has nothing to do with your "want to set to open a file inside the folder". You can access indvidual files via each element in entryList() or entryInfoList(), as you please.

                1 Reply Last reply
                3

                • Login

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