Add a function to create aa new directory
This commit is contained in:
@@ -26,7 +26,10 @@
|
|||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include <simgear_config.h>
|
#include <simgear_config.h>
|
||||||
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "sg_path.hxx"
|
#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_list sgPathSplit( const string &search_path ) {
|
||||||
string tmp = search_path;
|
string tmp = search_path;
|
||||||
string_list result;
|
string_list result;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#ifndef _SG_PATH_HXX
|
#ifndef _SG_PATH_HXX
|
||||||
#define _SG_PATH_HXX
|
#define _SG_PATH_HXX
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
@@ -132,6 +133,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool exists() const;
|
bool exists() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the designated directory.
|
||||||
|
*/
|
||||||
|
void create_dir(mode_t mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void fix();
|
void fix();
|
||||||
|
|||||||
Reference in New Issue
Block a user