Results 1 to 15 of 15

Thread: Save File in another Folder

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Save File in another Folder

    I'm not sure how would you want to create a subdirectory of a directory that doesn't exist...

    Qt Code:
    1. #include <QDir>
    2. #include <QtDebug>
    3.  
    4. int main(){
    5. QDir dir("logs");
    6. qDebug() << "Dir:" << dir.absolutePath();
    7. qDebug() << "Exists:" << dir.exists();
    8. if(!dir.exists()){
    9. // if dir doesn't exist, you can't create a subdirectory in it
    10. // [1]
    11. dir = QDir::current();
    12. qDebug() << "Current dir:" << dir.absolutePath();
    13. if(dir.exists()){
    14. qDebug() << "Current dir exits...";
    15. dir.mkdir("logs");
    16. }
    17. // [2]
    18. // dir.mkpath("logs");
    19. }
    20. QDir dircheck("logs");
    21. qDebug() << "Exists:" << dircheck.exists();
    22. return 0;
    23. }
    To copy to clipboard, switch view to plain text mode 

    Use either [1] or [2].

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

    GonzoFist (20th April 2010)

  3. #2
    Join Date
    Mar 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: Save File in another Folder

    Ah yes of course, I cant create a subdirectory in a not existing folder!
    I changed my Code to
    Qt Code:
    1. QDir dir("logs");
    2. if(!dir.exists())
    3. {
    4. dir = QDir::current();
    5. dir.mkdir("logs");
    6. }
    To copy to clipboard, switch view to plain text mode 

    And now it works just as I wanted it to.
    Thanks wysota, your the man!

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Save File in another Folder

    This would be simpler:
    Qt Code:
    1. QDir::current().mkpath("logs");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Moving File/Folder in Qt
    By arpspatel in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2010, 02:37
  2. Release folder - 1 .exe file only
    By Swankee in forum Qt Tools
    Replies: 6
    Last Post: 21st December 2009, 23:43
  3. Can't create folder if file with same name exists
    By Barry79 in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2009, 17:33
  4. Replies: 2
    Last Post: 27th October 2007, 19:16
  5. Password on local file/folder
    By icebox25 in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2007, 17:33

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.