Results 1 to 13 of 13

Thread: remove directory empty or not empty

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: remove directory empty or not empty

    Quote Originally Posted by raphaelf View Post
    Hi everybody,

    I have a folder "artistx". This folder could be empty or not.
    I would like to delete folder "artistx" and if it contains files or folder or not, i would like to delete it.
    I tried like this: (I can just remove the folder if the folder is empty)

    Qt Code:
    1. QString artistDirectory(path + "/" + artist);
    2. QMessageBox::information(this,"",artistDirectory);
    3. QDir directoryTodelete;
    4.  
    5.  
    6. directoryTodelete.rmpath(artistDirectory);
    To copy to clipboard, switch view to plain text mode 

    Remove line SqlLog & insert the full path to dir be remove....

    DownDir_RM("c:\\") remove all file!!
    Bee sure evry time the fulla path insert!!





    Qt Code:
    1. bool qt_unlink(QString fullFileName)
    2. {
    3. QFile f( fullFileName );
    4. if ( is_file( fullFileName ) ) {
    5. if (f.remove()) {
    6. return true;
    7. }
    8. }
    9. return false;
    10. }
    11.  
    12. void DownDir_RM(const QString d)
    13. {
    14. QDir dir(d);
    15. SqlLog("order to delete dir:"+d+" ");
    16. if (dir.exists())
    17. {
    18. const QFileInfoList list = dir.entryInfoList();
    19. for (int l = 0; l < list.size(); l++)
    20. {
    21. fi = list.at(l);
    22. if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..")
    23. DownDir_RM(fi.absoluteFilePath());
    24. else if (fi.isFile())
    25. {
    26. bool ret = qt_unlink(fi.absoluteFilePath());
    27. if (!ret)
    28. SqlLog("Can't remove: " + fi.absoluteFilePath() + " (write-protect?)");
    29. }
    30.  
    31. }
    32. SqlLog("Remove: " + d + " ");
    33. dir.rmdir(d);
    34.  
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

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

    raphaelf (27th October 2006)

Similar Threads

  1. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54
  2. 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.