该代码用于一次性创建多级目录:
#include <io.h>
#include <iostream>
#include <Windows.h>
#include <direct.h>
int main()
{
char szPath[128] = { 0x00 };
sprintf_s(szPath, 128, "%s/%d/%d/", "D:/SVNCode", 10100703, 1);
char* szBefore = szPath;
while (*szBefore)
{
if (*szBefore == '/')
{
char szDir[128] = { 0x00 };
strncpy_s(szDir, 128,szPath, szBefore - szPath);
int nRet = 0;
if (_access(szDir, 0) != 0)
nRet = _mkdir(szDir);
}
szBefore++;
}
if (_access(szPath, 0) != 0)
_mkdir(szPath);
DWORD dwError = GetLastError();
int n = 0;
return 0;
}
本文介绍了一种使用C++实现的批量创建多级目录的方法。通过遍历路径字符串中的每一个字符,当遇到'/'时创建对应的子目录,确保在Windows环境下能够成功创建所需的目录结构。
577

被折叠的 条评论
为什么被折叠?



