c++创建文件夹以及子文件夹
c++创建⽂件夹以及⼦⽂件夹#ifdef WIN32
#include <io.h>
#include <direct.h>
#else
#include <unistd.h>
僵尸围城成就#include <sys/stat.h>
#endif
#include <stdint.h>
#include <string>
#define MAX_PATH_LEN 256
#ifdef WIN32
#define ACCESS(fileName,accessMode) _access(fileName,accessMode)伦敦奥运会中国女排
#define MKDIR(path) _mkdir(path)
#else
#define ACCESS(fileName,accessMode) access(fileName,accessMode)
#define MKDIR(path) mkdir(path,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
#endif
// 从左到右依次判断⽂件夹是否存在,不存在就创建
// example: /home/root/mkdir/1/2/3/4/
// 注意:最后⼀个如果是⽂件夹的话,需要加上 '\' 或者 '/'
int32_t createDirectory(const std::string &directoryPath)
{
上海浦东游泳馆
uint32_t dirPathLen = directoryPath.length();
if (dirPathLen > MAX_PATH_LEN)
{
return -1;
}
char tmpDirPath[MAX_PATH_LEN] = { 0 };
for (uint32_t i = 0; i < dirPathLen; ++i)
{
tmpDirPath[i] = directoryPath[i];
if (tmpDirPath[i] == '\\' || tmpDirPath[i] == '/')
{
if (ACCESS(tmpDirPath, 0) != 0)
{
int32_t ret = MKDIR(tmpDirPath);
if (ret != 0)
{
return ret;
}
}
}
}
return0;
}
int32_t main(int32_t argc, char *argv[])
{
if (argc == 2)
{美国黑帮电影
return createDirectory(argv[1]);
}
return0;周立波宁波
网页历史记录恢复}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。