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. i want remove Directory
Forum Update on Monday, May 27th 2025

i want remove Directory

Scheduled Pinned Locked Moved Solved General and Desktop
removedirectoryqprocess
7 Posts 2 Posters 9.3k 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.
  • F Offline
    F Offline
    ForestPoem
    wrote on 7 Jan 2016, 06:23 last edited by ForestPoem 1 Jul 2016, 06:32
    #1

    Hi.
    i want remove folder
    QDir dir1;
    dir.remove("TEST");

    Fail.... because
    There is a subfolder.
    TEST
    └A
    └B
    another way

     QProcess  pProcess = new QProcess;
    QString total;
        total="TEST";
            list1<<"-r"+total;
            pProcess->execute("rm",list1);
    

    This failure

    rm: Inappropriate options -- 'L'

    R 1 Reply Last reply 7 Jan 2016, 06:41
    0
    • F ForestPoem
      7 Jan 2016, 06:23

      Hi.
      i want remove folder
      QDir dir1;
      dir.remove("TEST");

      Fail.... because
      There is a subfolder.
      TEST
      └A
      └B
      another way

       QProcess  pProcess = new QProcess;
      QString total;
          total="TEST";
              list1<<"-r"+total;
              pProcess->execute("rm",list1);
      

      This failure

      rm: Inappropriate options -- 'L'

      R Offline
      R Offline
      Ratzz
      wrote on 7 Jan 2016, 06:41 last edited by
      #2

      @ForestPoem
      For Qt5 you can try

      QDir dir("C:\\Path\\To\\Folder\\Here");
      dir.removeRecursively();
      

      --Alles ist gut.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        ForestPoem
        wrote on 7 Jan 2016, 06:43 last edited by ForestPoem 1 Jul 2016, 06:43
        #3

        @Ratzz
        thank.
        but my QT ver 4.8

        R 1 Reply Last reply 7 Jan 2016, 06:45
        0
        • F ForestPoem
          7 Jan 2016, 06:43

          @Ratzz
          thank.
          but my QT ver 4.8

          R Offline
          R Offline
          Ratzz
          wrote on 7 Jan 2016, 06:45 last edited by Ratzz 1 Jul 2016, 07:39
          #4

          @ForestPoem
          You may try this https://john.nachtimwald.com/2010/06/08/qt-remove-directory-and-its-contents/

          --Alles ist gut.

          F 1 Reply Last reply 7 Jan 2016, 06:55
          0
          • R Ratzz
            7 Jan 2016, 06:45

            @ForestPoem
            You may try this https://john.nachtimwald.com/2010/06/08/qt-remove-directory-and-its-contents/

            F Offline
            F Offline
            ForestPoem
            wrote on 7 Jan 2016, 06:55 last edited by ForestPoem 1 Jul 2016, 06:55
            #5

            @Ratzz

            Yes I have tried before.
            not remove.....

            .cpp
            bool ResetSetting::removeDir(const QString & dirName)
            {
            bool result = true;
            QDir dir(dirName);

            if (dir.exists(dirName)) {
                Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
                    if (info.isDir()) {
                        result = removeDir(info.absoluteFilePath());
                    }
                    else {
                        result = QFile::remove(info.absoluteFilePath());
                    }
            
                    if (!result) {
                        return result;
                    }
                }
                result = dir.rmdir(dirName);
            }
            return result;
            

            }
            ////////////////////////////////////////////
            .h
            static bool removeDir(const QString &dirName);

            ///////////////////////////////////////////

            removeDir("TEST");

            R 1 Reply Last reply 7 Jan 2016, 07:05
            0
            • F ForestPoem
              7 Jan 2016, 06:55

              @Ratzz

              Yes I have tried before.
              not remove.....

              .cpp
              bool ResetSetting::removeDir(const QString & dirName)
              {
              bool result = true;
              QDir dir(dirName);

              if (dir.exists(dirName)) {
                  Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
                      if (info.isDir()) {
                          result = removeDir(info.absoluteFilePath());
                      }
                      else {
                          result = QFile::remove(info.absoluteFilePath());
                      }
              
                      if (!result) {
                          return result;
                      }
                  }
                  result = dir.rmdir(dirName);
              }
              return result;
              

              }
              ////////////////////////////////////////////
              .h
              static bool removeDir(const QString &dirName);

              ///////////////////////////////////////////

              removeDir("TEST");

              R Offline
              R Offline
              Ratzz
              wrote on 7 Jan 2016, 07:05 last edited by Ratzz 1 Jul 2016, 07:11
              #6

              @ForestPoem
              I tried the same code you pasted. Works fine even for subfolders with contents.
              Where do you pass the QString dirName?
              You should pass the full path name of directory

                  QString dir="C:/Users/Path_to_test/TEST";
                  removeDir(dir);

              --Alles ist gut.

              F 1 Reply Last reply 7 Jan 2016, 07:23
              1
              • R Ratzz
                7 Jan 2016, 07:05

                @ForestPoem
                I tried the same code you pasted. Works fine even for subfolders with contents.
                Where do you pass the QString dirName?
                You should pass the full path name of directory

                    QString dir="C:/Users/Path_to_test/TEST";
                    removeDir(dir);
                F Offline
                F Offline
                ForestPoem
                wrote on 7 Jan 2016, 07:23 last edited by
                #7

                @Ratzz
                Did you use a relative path. And I've solved another way thanks

                1 Reply Last reply
                0

                2/7

                7 Jan 2016, 06:41

                topic:navigator.unread, 5
                • Login

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