[SOLVED] QDir::exists(const QString & name) and dirs



  • Dirs. Is this function will work with them or only with files. If no, how can I review exists of dir.



  • If you want to know if a file exists use,

    @
    #include <QFile>

    bool return;

    QFile filename("location/of/file");
    return = filename.exists();
    if(return == true){
    // success
    }
    else{
    // failed
    }
    @

    I would assume QDir would be the same way...aka replace QFile with QDir.



  • [quote author="tucnak" date="1325541840"]Dirs. Is this function will work with them or only with files. If no, how can I review exists of dir.[/quote]

    Instead of asking and waiting for someone to answer, you could just try it yourself. Should be manageable to create this code independently:

    @
    qDebug() << "existing dir: " << QDir("/path/to/existing/dir-or-file").exists();
    qDebug() << "missing dir: " << QDir("/path/to/non-existing/dir-or-file").exists();
    @

    For further research: QFileInfo, including exists(), isDir(), isFile().

    You could have stumbled over this class by reading [[Doc:QDir]] API docs. It's mentioned in the "See also" section and even at the description of QDir::exists(). Is it really that hard to click on the link?



  • Thanks, Volker. It was informative.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.