#include <sys/stat.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s = "blah/deep/deeper/deeply";
bool done = false;
mode_t perms = S_IRWXU | S_IRWXG;
unsigned int last_found = 0;
while (!done)
{
unsigned int posn = s.find("/", last_found);
if (posn == -1)
{ done = true;
}
else
{ cout << "making: " << s.substr(0, posn);
int result = mkdir(s.substr(0, posn).c_str(), perms);
if (result && errno != EEXIST)
{ cout << "can't! - " << (char*)strerror(errno) << endl;
}
else
{ cout << "OK!" << endl;
}
last_found = posn + 1;
} } }
--
MattWalsh - 08 Jan 2006