Results 1 to 20 of 20

Thread: How to remove empty folders?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default How to remove empty folders?

    Hi all

    Working on Qt4.2 on my mac intel machine.


    Qt Code:
    1. void MainWindow::ClearDir(QString dirRoot)
    2. {
    3. ClearAll(dirRoot);
    4. QDir d(dirRoot);
    5. d.cdUp();
    6. d.rmdir(dirRoot);
    7. }
    8.  
    9. /*Function for erasing Folder*/
    10.  
    11. void MainWindow:: ClearAll(QString dirViewPath)
    12. {
    13. QDir dirPath(dirViewPath);
    14. QList<QFileInfo> infLst = dirPath.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
    15.  
    16. foreach(QFileInfo finfo, infLst )
    17. {
    18. if(finfo.isDir() )
    19. {
    20. ClearAll(finfo.absoluteFilePath());
    21. dirPath.rmdir(finfo.absoluteFilePath());
    22. }
    23. else
    24. { //file
    25. QString fileName = dirViewPath + "/" + finfo.fileName();
    26. dirPath.remove(finfo.absoluteFilePath());
    27. }
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 
    Using this code, I try to remove the existing dir selected using QFileDialog, I will be able to remove all the files but empty folders are left.
    Always Believe in Urself
    Merry

  2. The following user says thank you to merry for this useful post:

    yogeshgokul (16th December 2008)

Similar Threads

  1. remove node in xml file
    By mattia in forum Newbie
    Replies: 1
    Last Post: 6th March 2008, 13:25
  2. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 07:30
  3. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58

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
  •  
Qt is a trademark of The Qt Company.