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. help in QDirIterator to a text file
Forum Updated to NodeBB v4.3 + New Features

help in QDirIterator to a text file

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 6 Posters 4.1k Views 2 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.
  • M Offline
    M Offline
    mpergand
    wrote on 17 Jul 2018, 17:35 last edited by mpergand
    #15

    You return nothing, that's the cause.

    @JonB
    Your're right ofcourse, in fact it doesn"t even compile.

    A 1 Reply Last reply 17 Jul 2018, 17:38
    1
    • M mpergand
      17 Jul 2018, 17:35

      You return nothing, that's the cause.

      @JonB
      Your're right ofcourse, in fact it doesn"t even compile.

      A Offline
      A Offline
      Abrar
      wrote on 17 Jul 2018, 17:38 last edited by
      #16

      @mpergand thanks a lot it's working

      1 Reply Last reply
      0
      • J JonB
        17 Jul 2018, 17:29

        @Abrar
        while (it.hasNext) {

        I don't do C++, but shouldn't that be it.hasNext()?

        A Offline
        A Offline
        Abrar
        wrote on 17 Jul 2018, 17:49 last edited by
        #17

        @JonB Yes you are right.
        That was my typing mistake.
        @mpergand it was compiling.

        J 1 Reply Last reply 17 Jul 2018, 17:54
        0
        • A Abrar
          17 Jul 2018, 17:49

          @JonB Yes you are right.
          That was my typing mistake.
          @mpergand it was compiling.

          J Offline
          J Offline
          JonB
          wrote on 17 Jul 2018, 17:54 last edited by JonB
          #18

          @Abrar
          Never type "your code", always copy & paste! That would save a fair proportion of questions/answers in the forum!

          A 1 Reply Last reply 17 Jul 2018, 17:59
          1
          • J JonB
            17 Jul 2018, 17:54

            @Abrar
            Never type "your code", always copy & paste! That would save a fair proportion of questions/answers in the forum!

            A Offline
            A Offline
            Abrar
            wrote on 17 Jul 2018, 17:59 last edited by
            #19

            @JonB thanks for your suggestion.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              saber
              wrote on 8 Aug 2018, 07:26 last edited by saber 8 Oct 2018, 03:58
              #20

              @Abrar made a function that works .but problems is it takes a long time to make the text file (not enter every folder and get the name).it takes long time if the folder tree is complex.

              i wonder how the tree package that @mrjj pointing is take fraction of the time to make that same text file.

              here is the code.

              int pat = 0;
              QString strDir;
              QString getFileFolderTree(const QString &path)
              {
                  
                  // ├
              
                  // └
              
                  // │
              
                  // ──
              
              
                  pat++;
              
                  QDir dir(path);
                  //dir.setSorting(QDir::DirsFirst);
                  //dir.setNameFilters(QStringList("*"));
                  dir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
                  QStringList dList = dir.entryList();
                  for (int i = 0; i < dList.count(); ++i) {
                      QString newPath = QString("%1/%2").arg(dir.absolutePath()).arg(dList.at(i));
              
                      QString strPat = "├── ";
                      for (int i = 1; i < pat; i++) {
                          strPat.insert(0, "│   ");
                      }
              
                      if (i == dList.count() - 1) {
                          int pos = strPat.count() - 4;
                          strPat = strPat.replace(pos, 1, "└");
                      }
              
                      strDir.append(strPat + QDir(dList.at(i)).dirName() + "\n");
              
                      getFileFolderTree(newPath);
                  }
              
                  pat--;
              
                  dir.setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
                  QStringList fList = dir.entryList();
                  for (int i = 0; i < fList.count(); i++) {
              
                      QString strPat = "├── ";
                      for (int j = 1; j < pat + 1; j++) {
                          strPat.insert(0, "│   ");
                      }
              
                      if (i == fList.count() - 1) {
                          strPat = strPat.replace(strPat.count() - 4, 1, "└");
                      }
              
                      strDir.append(strPat + fList[i] + "\n");
                  }
              
              //    QDirIterator it(path, QDir::AllEntries | QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::System);
              //    while (it.hasNext()) {
              //        it.next();
              //        if (it.fileInfo().isDir()) {
              //            qDebug() << it.fileInfo().path();
              //            getFileFolderTree(it.filePath());
              //        }
              //        qDebug() << "\t" << it.filePath();
              //    }
              
                  //qDebug() << strDir;
              
                  if (!strDir.count())
                      strDir.append(".\n");
              
                  QFile file("/home/abrar/Desktop/UI.txt");
                  file.open(QIODevice::Text | QIODevice::ReadWrite | QIODevice::Truncate);
                  QTextStream out(&file);
                  out << strDir;
                  file.close();
              
              
                  return QString();
              }
              
              

              so i need some help to dicress the time to make the text file .
              help! help! help!
              thanks.

              J 1 Reply Last reply 8 Aug 2018, 09:40
              0
              • S saber
                8 Aug 2018, 07:26

                @Abrar made a function that works .but problems is it takes a long time to make the text file (not enter every folder and get the name).it takes long time if the folder tree is complex.

                i wonder how the tree package that @mrjj pointing is take fraction of the time to make that same text file.

                here is the code.

                int pat = 0;
                QString strDir;
                QString getFileFolderTree(const QString &path)
                {
                    
                    // ├
                
                    // └
                
                    // │
                
                    // ──
                
                
                    pat++;
                
                    QDir dir(path);
                    //dir.setSorting(QDir::DirsFirst);
                    //dir.setNameFilters(QStringList("*"));
                    dir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
                    QStringList dList = dir.entryList();
                    for (int i = 0; i < dList.count(); ++i) {
                        QString newPath = QString("%1/%2").arg(dir.absolutePath()).arg(dList.at(i));
                
                        QString strPat = "├── ";
                        for (int i = 1; i < pat; i++) {
                            strPat.insert(0, "│   ");
                        }
                
                        if (i == dList.count() - 1) {
                            int pos = strPat.count() - 4;
                            strPat = strPat.replace(pos, 1, "└");
                        }
                
                        strDir.append(strPat + QDir(dList.at(i)).dirName() + "\n");
                
                        getFileFolderTree(newPath);
                    }
                
                    pat--;
                
                    dir.setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
                    QStringList fList = dir.entryList();
                    for (int i = 0; i < fList.count(); i++) {
                
                        QString strPat = "├── ";
                        for (int j = 1; j < pat + 1; j++) {
                            strPat.insert(0, "│   ");
                        }
                
                        if (i == fList.count() - 1) {
                            strPat = strPat.replace(strPat.count() - 4, 1, "└");
                        }
                
                        strDir.append(strPat + fList[i] + "\n");
                    }
                
                //    QDirIterator it(path, QDir::AllEntries | QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::System);
                //    while (it.hasNext()) {
                //        it.next();
                //        if (it.fileInfo().isDir()) {
                //            qDebug() << it.fileInfo().path();
                //            getFileFolderTree(it.filePath());
                //        }
                //        qDebug() << "\t" << it.filePath();
                //    }
                
                    //qDebug() << strDir;
                
                    if (!strDir.count())
                        strDir.append(".\n");
                
                    QFile file("/home/abrar/Desktop/UI.txt");
                    file.open(QIODevice::Text | QIODevice::ReadWrite | QIODevice::Truncate);
                    QTextStream out(&file);
                    out << strDir;
                    file.close();
                
                
                    return QString();
                }
                
                

                so i need some help to dicress the time to make the text file .
                help! help! help!
                thanks.

                J Offline
                J Offline
                JonB
                wrote on 8 Aug 2018, 09:40 last edited by
                #21

                @saber
                It shouldn't take long. But you don't say how many files/directories there are --- if it's thousands, it will take longer....

                You should put debug statements in or run under debugger to discover just which part is taking the time if you expect anybody to be able to help you. Saying "help! help! help!" doesn't do it.

                S 1 Reply Last reply 10 Aug 2018, 04:16
                1
                • J JonB
                  8 Aug 2018, 09:40

                  @saber
                  It shouldn't take long. But you don't say how many files/directories there are --- if it's thousands, it will take longer....

                  You should put debug statements in or run under debugger to discover just which part is taking the time if you expect anybody to be able to help you. Saying "help! help! help!" doesn't do it.

                  S Offline
                  S Offline
                  saber
                  wrote on 10 Aug 2018, 04:16 last edited by
                  #22

                  @JonB
                  thanks.
                  as in my Linux system debuger is not working (i tried to fix), i can't test it.

                  jsulmJ J 2 Replies Last reply 10 Aug 2018, 06:03
                  0
                  • S saber
                    10 Aug 2018, 04:16

                    @JonB
                    thanks.
                    as in my Linux system debuger is not working (i tried to fix), i can't test it.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 10 Aug 2018, 06:03 last edited by
                    #23

                    @saber You still can put some debug output in your code as @JonB suggested

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

                    1 Reply Last reply
                    0
                    • S saber
                      10 Aug 2018, 04:16

                      @JonB
                      thanks.
                      as in my Linux system debuger is not working (i tried to fix), i can't test it.

                      J Offline
                      J Offline
                      JonB
                      wrote on 10 Aug 2018, 06:55 last edited by
                      #24

                      @saber
                      If you mean your gdb is not working you should get it working.

                      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