Results 1 to 10 of 10

Thread: Deleting a Folder

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    14
    Thanked 41 Times in 35 Posts

    Default Re: Deleting a Folder

    I don't have time right now to go through your code, but in a past project, I wrote a recursive function to do just what you're wanting to do, you pass it the parent directory path as a string, and it does the rest for you...

    Qt Code:
    1. void VideoManagerPage::deleteVideoDirectory(QString video_dir)
    2. {
    3. QDir dvd_dir(video_dir);
    4.  
    5. //First delete any files in the current directory
    6. QFileInfoList files = dvd_dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files);
    7. for(int file = 0; file < files.count(); file++)
    8. {
    9. dvd_dir.remove(files.at(file).fileName());
    10. }
    11.  
    12. //Now recursively delete any child directories
    13. QFileInfoList dirs = dvd_dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs);
    14. for(int dir = 0; dir < dirs.count(); dir++)
    15. {
    16. this->deleteVideoDirectory(dirs.at(dir).absoluteFilePath());
    17. }
    18.  
    19. //Finally, remove empty parent directory
    20. dvd_dir.rmdir(dvd_dir.path());
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by JimDaniel; 7th June 2008 at 18:46.

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

    missoni (6th April 2011)

Similar Threads

  1. Avoiding unnecessary files and folder in Impelementation
    By salmanmanekia in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2008, 14:54
  2. QFtp: entering deep folder (cd)
    By Raccoon29 in forum Newbie
    Replies: 1
    Last Post: 13th May 2008, 09:28
  3. Deleting QProcess
    By user_mail07 in forum Qt Programming
    Replies: 7
    Last Post: 29th January 2008, 18:55
  4. Replies: 2
    Last Post: 27th October 2007, 18:16
  5. [QT3] Temporary Folder Temporary File
    By Senpai in forum Qt Programming
    Replies: 10
    Last Post: 6th October 2006, 10: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
  •  
Qt is a trademark of The Qt Company.