PDA

View Full Version : Trouble with proper syntax for directorys



prophet0
21st February 2012, 19:55
What I'm trying to accomplish is have my application check to see if some directories exist

if ttm does not make it if it does then go on to clients if it don't exist then make it and if its there continue to clientdir and campaigndir

this is the current solution im currently trying to figure out..


QDir ttmDir("/ttm");
QDir clientsDir("/ttm/clients");
QDir clientDir("/ttm/clients/" + clientID.toInt());
QDir campaignDir(campaignID);


//Check to see if "/ttm" is there or not if not make it..
if(!ttmDir.exists())
{
QDir().mkdir("/ttm");
qDebug() << "ttm didnt exist creating it";
}
if (ttmDir.exists())
{
qDebug() << "ttm exist so lets check clientsDir";

if(!clientsDir.exists())
{
qDebug() << "clientsDir does not exist creating it...";
QDir().mkdir("/ttm/clients");
}else
{
qDebug() << "clientsDir exist lets check clientDir";
}

}
if (!clientDir.exists())
{
qDebug() << "clientDir does not exist creating it...";
QDir().mkdir("/ttm/clients/" + clientID.toInt());

}


"QDir().mkdir("/ttm/clients/" + clientID.toInt());" = 16

but it will not create the folder 16 within /ttm/clients/ ie: "/ttm/clients/16"

nothing I do will make it work i checked file permissions and even tried using system(""); to accomplish this task but still will not work..

does anyone have any suggestions?

boudie
21st February 2012, 22:34
A better way to test if a directory exists might be
yourDir.cd(dirName)
If it returns true, you are sure it exists AND is readable.

Furthermore, you are using mkdir() as a static function which it isn't.

prophet0
21st February 2012, 22:42
thanks :) i fixed it with the following code this is just a rough draft i need to make it all automated but here is my code for anyone else looking for something close to this



QDir ttmDir("/ttm");
QDir clientsDir("/ttm/clients");
QDir clientDir("/ttm/clients/" + clientID);
QString clientString = "/ttm/clients/" + clientID;
QDir campaignDir("/ttm/clients/" + clientID + QDir::separator() + campaignID);
QString campaignString = "/ttm/clients/" + clientID + QDir::separator() + campaignID;


//Check to see if "/ttm" is there or not if not make it..
if(!ttmDir.exists())
{
QDir().mkdir("/ttm");
QDir().setCurrent("/ttm/");
qDebug() << "ttm didnt exist creating it";
ui->progressBar->setValue(40);

}
if (ttmDir.exists())
{
qDebug() << "ttm exist so lets check clientsDir";

if(!clientsDir.exists())
{
qDebug() << "clientsDir does not exist creating it...";
QDir().mkdir("/ttm/clients");
QDir().setCurrent("/ttm/clients/");
ui->progressBar->setValue(45);
}else
{
qDebug() << "clientsDir exist lets check clientDir";
QDir().setCurrent("/ttm/clients/");
}

}
if (!clientDir.exists())
{
qDebug() << "clientDir does not exist creating it...";
QDir().mkdir(clientString);
QDir().setCurrent(clientString);
ui->progressBar->setValue(50);

}else
{
qDebug() << clientString;
qDebug() << "clientDir exists lets check campaignDir";
ui->progressBar->setValue(55);
}
if(!campaignDir.exists())
{
qDebug() << "campaignDir does not exist creating it...";
QDir().mkdir(campaignString);
QDir().setCurrent(campaignString);
ui->progressBar->setValue(60);
}else
{
qDebug() << "campaignDir exists lets download the content now...";
ui->progressBar->setValue(65);
}