Add a function to create aa new directory

This commit is contained in:
ehofman
2005-12-17 15:06:56 +00:00
parent 3f0bcc9568
commit 4eb74a3c93
2 changed files with 26 additions and 0 deletions

View File

@@ -26,7 +26,10 @@
#include <simgear/compiler.h>
#include <simgear_config.h>
#include <simgear/debug/logstream.hxx>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include "sg_path.hxx"
@@ -183,6 +186,23 @@ bool SGPath::exists() const {
}
void SGPath::create_dir( mode_t mode ) {
string_list dirlist = sgPathSplit(dir());
SGPath dir = dirlist[0];
int i;
for(i=1; dir.exists() && i < dirlist.size(); i++) {
dir.add(dirlist[i]);
}
for(;i < dirlist.size(); i++) {
string subdir = dirlist[i];
if ( mkdir( subdir.c_str(), mode) ) {
SG_LOG( SG_IO, SG_ALERT, "Error creating directory: " + dir.str() );
break;
}
dir.add(subdir);
}
}
string_list sgPathSplit( const string &search_path ) {
string tmp = search_path;
string_list result;

View File

@@ -29,6 +29,7 @@
#ifndef _SG_PATH_HXX
#define _SG_PATH_HXX
#include <sys/types.h>
#include <simgear/compiler.h>
#include STL_STRING
@@ -132,6 +133,11 @@ public:
*/
bool exists() const;
/**
* Create the designated directory.
*/
void create_dir(mode_t mode);
private:
void fix();