#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

Topic revision: r1 - 09 Jan 2006 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback