void sampleDete::isDirExist(const QString &path) { qDebug()<<"path: "<<path; //"./images/2024-04-15-08-56-18/2024-04-15-08-56-18_1" QDir dir(path); if(!dir.exists()) { if(!dir.mkpath(path)) { qDebug()<<"mkdir path fail: "<<path; } } } //在当前文件夹下创建了一个嵌套的目录./images/2024-04-15-08-56-18/2024-04-15-08-56-18_1/images/2024-04-15-08-56-18/2024-04-15-08-56-18_1
原因:
QDir dir(path);这里已经存在了一个路径 path
dir.mkpath(path);//在创建目录的时候再次包含 path 导致嵌套
修改代码如下即可解决
void sampleDete::isDirExist(const QString &path) { qDebug()<<"path: "<<path; //"./images/2024-04-15-08-56-18/2024-04-15-08-56-18_1" QDir dir; //修改 if(!dir.exists(path)) //修改 { if(!dir.mkpath(path)) { qDebug()<<"mkdir path fail: "<<path; } } }
标签:const,void,嵌套,QDir,QString,path,目录 From: https://www.cnblogs.com/WU20/p/18135225