void createDir( const char *dir )
{
int offset = 0;
string str1 = dir;
size_t np = str1.find('/', offset);
while (np != string::npos)
{
string now_path = str1.substr(0, np);
if (_access(now_path.c_str(), 0) == -1)//判断该目录是否存在
{
mkdir(now_path.c_str()); //创建目录
}
offset = np+1;
np = str1.find('/', offset);
int c = 0;
}
{
int offset = 0;
string str1 = dir;
size_t np = str1.find('/', offset);
while (np != string::npos)
{
string now_path = str1.substr(0, np);
if (_access(now_path.c_str(), 0) == -1)//判断该目录是否存在
{
mkdir(now_path.c_str()); //创建目录
}
offset = np+1;
np = str1.find('/', offset);
int c = 0;
}
}
用法 传入"aa/bb/cc.jpg" 程序会自动在当前目录下依次创建 aa aa/bb