PDA

View Full Version : QDir::mkpath



drescherjm
5th March 2009, 00:00
I am trying to figure out the intend usage of QDir::mkpath

On Qt 4.3 on windows XP


Qdir dir("John");

dir.mkpath("Kathy");

The result is John/Kathy which is not what I expected especially because my intended usage was as follows.


QDir dir("John");

if (!dir.exists()) {
dir.mkpath("John");
}


However the result is

John/John
is created.

I tried

QDir dir("John");

if (!dir.exists()) {
dir.mkpath(".");
}


and got what I wanted (created just John in the current folder) however I am unsure that this will work on all platforms.

Also if you


QDir dir("John");

if (!dir.exists()) {
dir.mkpath("");
}


it exits with false because the path can not be empty.

JimDaniel
5th March 2009, 01:41
I think what you want to do is just instantiate an empty QDir, which will default to the program directory, then you can use mkpath to make a path wherever you want and it will create the proper directory structure for you, if it doesn't exist already:



QDir myDir();
if(!myDir.exists("John"))
{
myDir.mkpath("John/Kathy/Ben/George/Ringo");
}


Or maybe that's not what you intend.

drescherjm
5th March 2009, 05:35
:D

Thanks. Sounds reasonable.