I want to create a folder named sessionname
. If a folder with this name already exists it is fine, and I don't want to do anything.
Right now I do this:
finalpath = "/home/Documents"
finalpath.append(path + "/" + sessionname);
if (mkdir(finalpath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1)
{
//INVALID PATH
std::cout << "path is invalid, cannot create sessionnamefolder" << std::endl;
throw std::exception();
}
This code errors, if the folder /home/Documents/sessionname
exists because the folder couldn't be created.
How can I check if mkdir
fails because the string was invalid or because the string was vaild but the folder already exists ?