Results 1 to 10 of 10

Thread: Delete Directory

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Delete Directory

    hi ,
    I want to delete a directory empty or not empty in a easier way.
    I dont want to use loop to iterate through the files and delete one by one.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    ...

    Ok sorry, you wanted empty or not...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    I want to delete a directory empty or not empty in a easier way.
    So, rmdir won't work in this case.
    See QDir::entryList() for a list of files and dirs. You need a recursive function to traverse the directory hierarchy and delete the files one by one.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Delete Directory

    Quote Originally Posted by AnithaRagupathy View Post
    hi ,
    I want to delete a directory empty or not empty in a easier way.
    I dont want to use loop to iterate through the files and delete one by one.
    There is no other way around. Qt has no "rm -rf", only "rmdir". See http://www.qtcentre.org/forum/p-recu...ostcount2.html.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    May be QProcess with system specific call such as "rm" with "-R -d".
    I guess windows has something similar too.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Oct 2007
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    I m a beginner.Plz bear with me.but how to use QProcess to delete directory.

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    QProcessI haven't used QProcess with Qt4 yet, but I can remember having some problems with Qt3 with some shell commands and arguments for those commands.
    However I can't see anything in the docs that points any such problems in Qt4, so it might work.
    If QProcess wont help you, you can try also system specific calls such as system().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Oct 2007
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    i didnt understand ...How this QProcess can be used to delete directory?

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    You will have to READ the QProcess doc for that.
    Ask if there is anything specific you don't understand.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  10. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delete Directory

    Using Qprocess to delete a directory is a dirty and non-portable method.
    It is better to use the filesystem API in Qt to do it.

Similar Threads

  1. How do I get QMAKE_CLEAN to delete a directory?
    By Chuk in forum Qt Programming
    Replies: 5
    Last Post: 6th February 2012, 20:19
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  3. error in compiling qtopia.....
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 11th January 2007, 10:10
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 16:38
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 13:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.