c++判断目录是否存在,不存在创建
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
bool chkFilePath(string strPath, bool bAutoCreate = true) { struct stat dirStat; int result = stat(strPath.c_str(), &dirStat); if ((result != 0) && (bAutoCreate)) { if (mkdir(strPath.c_str(), S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) cerr << "mkdir " << strPath << " false, errno:" << errno << " errmsg:" << strerror(errno) << endl; } return (result == 0); }
浙公网安备 33010602011771号