I'm not sure how would you want to create a subdirectory of a directory that doesn't exist...
#include <QDir>
#include <QtDebug>
int main(){
qDebug() << "Dir:" << dir.absolutePath();
qDebug() << "Exists:" << dir.exists();
if(!dir.exists()){
// if dir doesn't exist, you can't create a subdirectory in it
// [1]
qDebug() << "Current dir:" << dir.absolutePath();
if(dir.exists()){
qDebug() << "Current dir exits...";
dir.mkdir("logs");
}
// [2]
// dir.mkpath("logs");
}
qDebug() << "Exists:" << dircheck.exists();
return 0;
}
#include <QDir>
#include <QtDebug>
int main(){
QDir dir("logs");
qDebug() << "Dir:" << dir.absolutePath();
qDebug() << "Exists:" << dir.exists();
if(!dir.exists()){
// if dir doesn't exist, you can't create a subdirectory in it
// [1]
dir = QDir::current();
qDebug() << "Current dir:" << dir.absolutePath();
if(dir.exists()){
qDebug() << "Current dir exits...";
dir.mkdir("logs");
}
// [2]
// dir.mkpath("logs");
}
QDir dircheck("logs");
qDebug() << "Exists:" << dircheck.exists();
return 0;
}
To copy to clipboard, switch view to plain text mode
Use either [1] or [2].
Bookmarks