创建多层目录

 BOOL CTestToolCtr::CreateFolder(CString strNewFolder)
{
/**********************************************************************
[Name ]
CreateFolder [Function ]
创建文件夹 [Param ]
CString strNewFolder 创建的目录 [Return ]
TRUE: 创建成功
FALSE:创建失败 [Remarks ]
***********************************************************************/
if (PathFileExists(strNewFolder))
{
return FALSE;
}
else
{
return MakeDir((LPCTSTR)strNewFolder);
}
return TRUE;
} BOOL CTestToolCtr::MakeDir(const char* szPath)
{
char copy_path[];
memset(copy_path, , sizeof(copy_path)); int len = ;
char *last_mozi = NULL;
char *mozi = NULL;
char d_buf[], dd_buf[];
memset(d_buf, , sizeof(d_buf));
memset(dd_buf, , sizeof(dd_buf)); sprintf_s(copy_path, sizeof(copy_path), szPath);
len = strlen(copy_path);
last_mozi = CharPrev(copy_path, &copy_path[len]); if (last_mozi == (&copy_path[len-]))
{
if (copy_path[len-] == '\\' || copy_path[len-] == '/')
{
copy_path[len-] = 0x00;
}
} CharPrev(copy_path, copy_path);
mozi = CharNext(copy_path);
while (*mozi != '\0')
{
if (*mozi == '\\' || *mozi == '/')
{
memset(d_buf, , sizeof(d_buf));
memcpy(d_buf, copy_path, mozi-copy_path);
sprintf_s(dd_buf, sizeof(d_buf), "%s", d_buf);
if (!PathFileExists(dd_buf))
{
if (!CreateDirectory(dd_buf, NULL))
{
return FALSE;
}
}
}
mozi = CharNext(copy_path);
}
sprintf_s(dd_buf,sizeof(copy_path), "%s", copy_path); if (!PathFileExists(dd_buf))
{
if (!CreateDirectory(dd_buf,NULL))
{
return FALSE;
}
}
return TRUE;
}
04-25 11:59