循环创建文件夹

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

// 根据传入路径,创建出路径文件/夹
BOOL CheckPathExists(const CString &strPath, bool bFolder = true)
{
// If Folder is exists
int nIndex = strPath.ReverseFind(_T('\\'));
CString strTemp;
if(bFolder)
{
if(PathFileExists(strPath)) return TRUE;
}
else
{
strTemp = strPath.Left(nIndex);
if(PathFileExists(strTemp)) return TRUE;
}

// Create Folder
std::vector<CString> vecPath;
std::vector<CString>::iterator iter;
while(nIndex != -1)
{
strTemp = strPath.Left(nIndex);
if(strTemp.Right(1) != _T(':'))
vecPath.push_back(strTemp);
else break;

nIndex = strTemp.ReverseFind(_T('\\'));
}

if(vecPath.size() > 0)
{
for(iter = vecPath.end() - 1; iter != vecPath.begin(); -- iter)
{
strTemp = *iter;
CreateDirectory(strTemp, NULL);
}
// 顶级目录
CreateDirectory(vecPath[0], NULL);

if(bFolder) // 如果是文件夹
CreateDirectory(strPath, NULL);
}
return TRUE;
}