#include <io.h>
#include <direct.h>
void CreateDir(string filePath)
{
int m = 0, n;
string shortPath;
shortPath = filePath.substr(0, 2);
filePath = filePath.substr(3, filePath.size());
while(m >= 0)
{
m = filePath.find(“\\”);
shortPath += “\\” + filePath.substr(0, m);
n = _access(shortPath.c_str(), 0);
if(n == -1) {
_mkdir(shortPath.c_str());
}
filePath = filePath.substr(m + 1, filePath.size());
}
}
使用:
void main() {
CreateDir(“D:\\Log\\20200202”);
}