循环创建文件夹

2015-04-02 0 692
循环创建文件夹

// 根据传入路径,创建出路径文件/夹

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;

}


遇见资源网 c/c++ 循环创建文件夹 http://www.ox520.com/10040.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务