Qt Remove Directory

Qt Remove Directory

Qt have rich QDir class provides access to directory structures and their contents. QDir have function QDir::rmdir to remove directory. The directory must be empty for rmdir() to succeed. This Qt Remove Directory function Returns true if successful,  otherwise returns false. The problem is how Qt Remove Directory if that directory not empty? If you have non empty directory, you can use this Qt Remove Directory function to remove non empty directory with all subdirectory. This is a Qt Remove Directory function :

You can call this Qt Remove Directory function with this method :

If you have any question or method about this Qt Remove Directory, please share to us.

Source :


Hi, This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.

More Posts - Website

5 thoughts on “Qt Remove Directory

    • Hi AnCoward,

      Thank you for your comment. I think we can not use your method. I use your method and fail. The problem for this posting is how to remove not empty directory.

      This is like how to remove directory with sub directory and every directory is not empty. I am figured like this :
      We want to remove directory ‘a’ with all subdirectory and file in a.

      If you read QFile::remove( path ) documentation :
      bool QFile::remove ( const QString & fileName ) [static]
      This is an overloaded function.
      Removes the file specified by the fileName given.

      So, this function is to remove a file, not directory. Thank you for visiting my site

  1. Thank you! Your code works fine except that it does not handle hidden directories (very common under UNIX as directories starting with a dot). If you append QDir::Hidden to the list of flags then it handles these too :)

Leave a Reply

Your email address will not be published. Required fields are marked *