Browse Subversion Repository
Contents of /common/CreateDirectory.cpp
Parent Directory
| Revision Log
Revision 380 -
( show annotations)
( download)
( as text)
Sun May 16 11:35:05 2010 UTC
(14 years ago)
by satofumi
File MIME type: text/x-c++src
File size: 1019 byte(s)
shellViewer が動作するように調整
| 1 |
/*! |
| 2 |
\file |
| 3 |
\brief ディレクトリの作成 |
| 4 |
|
| 5 |
\author Satofumi KAMIMURA |
| 6 |
|
| 7 |
$Id$ |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "CreateDirectory.h" |
| 11 |
#include "ExistFile.h" |
| 12 |
#include "DetectOS.h" |
| 13 |
#ifdef WINDOWS_OS |
| 14 |
#include <direct.h> |
| 15 |
#else |
| 16 |
#include <sys/stat.h> |
| 17 |
#endif |
| 18 |
#include <string> |
| 19 |
|
| 20 |
|
| 21 |
bool beego::createDirectory(const char* directory) { |
| 22 |
|
| 23 |
// 末尾の '/' を無視してディレクトリ作成を行う |
| 24 |
std::string dir_path = directory; |
| 25 |
size_t n = dir_path.size(); |
| 26 |
if (directory[n - 1] == '/') { |
| 27 |
dir_path = dir_path.substr(0, n - 1); |
| 28 |
} |
| 29 |
std::string next_create = dir_path.substr(0, dir_path.find_last_of('/')); |
| 30 |
|
| 31 |
// !!! 書き込み権限があるか、を確認すべきかも |
| 32 |
if (existFile(dir_path.c_str())) { |
| 33 |
return true; |
| 34 |
} |
| 35 |
|
| 36 |
// ディレクトリの作成 |
| 37 |
#if defined(MinGW) |
| 38 |
return (mkdir(dir_path.c_str()) == 0) ? true : false; |
| 39 |
#elif defined(MSC) |
| 40 |
return (_mkdir(dir_path.c_str()) == 0) ? true : false; |
| 41 |
#else |
| 42 |
return (mkdir(dir_path.c_str(), 0755) == 0) ? true : false; |
| 43 |
#endif |
| 44 |
|
| 45 |
if (! createDirectory(next_create.c_str())) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
return true; |
| 50 |
} |
|