Hi Klaus!
You'd have to do all the checks yourself, before calling mkPath(). I think you'd have to iterate or recurse through deeper and deeper components of the path and do the checks using QFileInfo or something like that. Remember that mkPath can create multiple directories (if parents to the target directory don't exist), so it might be wiser to use mkDir() instead and create all those dirs yourself one at a time.
A snippet that more or less should do it:
QString pathtocreate;
// (absolute) foreach
(QString component, components
){ if(dir.exists(component)){
dir.cd(component);
} else {
// validate path
// ...
// for example:
// if(!finfo.isWritable()) return QString("Directory not writable");
bool r = dir.mkDir(component);
if(!r
) return QString("Could not create directory %1").
arg(dir.
absoluteFilePath(component
));
r = dir.cd(component);
if(!r
) return QString("Directory %1 not accessible").
arg(dir.
absoluteFilePath(component
));
}
}
QString pathtocreate; // (absolute)
QStringList components = pathtocreate.split('/');
QDir dir("/");
foreach(QString component, components){
if(dir.exists(component)){
dir.cd(component);
} else {
QFileInfo finfo(dir, component);
// validate path
// ...
// for example:
// if(!finfo.isWritable()) return QString("Directory not writable");
bool r = dir.mkDir(component);
if(!r) return QString("Could not create directory %1").arg(dir.absoluteFilePath(component));
r = dir.cd(component);
if(!r) return QString("Directory %1 not accessible").arg(dir.absoluteFilePath(component));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks