Checking if a folder exists (and creating folders) in Qt, C++

Checking if a folder exists (and creating folders) in Qt, C++

Asked on December 14, 2018 in Qt.
Add Comment


  • 3 Answer(s)

    The following  “Folder” exists :

    QDir("Folder").exists();
    

       Create  a new   folder  named as”MyFolder” :

     QDir().mkdir("MyFolder");
    
    Answered on December 14, 2018.
    Add Comment

    The following solution is  exists and  it does not  including intermediaries:

    QDir dir("path/to/dir");
    if (!dir.exists())
      dir.mkpath(".");
    
    Answered on December 14, 2018.
    Add Comment

    The best solution is:

    To use  QDir.mkpath() it returns true if the path already exists, in the other hand QDir.mkdir() returns false if the path already exists. So depending on this program  have to choose which fits better.

    Answered on December 14, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.