QDir中mkdir和mkpath的区别!
mkdir:
原型:bool QDir::mkdir(const QString &dirName) const
Creates a sub-directory called dirName.
Returns true on success; otherwise returns false.
If the directory already exists when this function is called, it will return false.
解释:
创建一个名为dirName的子目录
成功:返回true;失败:返回false
如果此函数调用时,该目录已经存在,将会返回false
mkpath:
原型:bool QDir::mkpath(const QString &dirPath) const
Creates the directory path dirPath.
The function will create all parent directories necessary to create the directory.
Returns true if successful; otherwise returns false.
If the path already exists when this function is called, it will return true.
解释:
创建一个目录路径
这个函数将会创建所有必需的父类目录
成功:返回true;失败:返回false
如果此函数调用时,该路径已经存在,此函数将会返回true
区别:如果要创建的目录存在,mkdir返回false,而mkpath返回true,另外mkpath里为路径或者目录,而mkdir必须为目录!!!
本文详细解析了QDir中的mkdir和mkpath函数,阐述了它们在创建目录时的不同行为。mkdir仅创建单个目录,且若目录已存在则返回false;mkpath创建整个目录路径,包括所有父目录,即使路径已存在也返回true。
2145

被折叠的 条评论
为什么被折叠?



