/***********************************************************************/
/* \函数名称:CopyDir
* \函数功能:复制文件夹
* \函数返回:bool
如果是true,复制成功,否则失败。
* \参数说明:
@param CString strSrcPath 源文件夹
@param CString strDstPath 目标文件夹
/***********************************************************************/
bool CopyDir(CString strSrcPath, CString strDstPath)
{
// 创建目标文件夹
CPath path(strDstPath);
if (path.FileExists() && path.IsDirectory())
{
}
else
{
if (!CreateDirectory(path.m_strPath, NULL))
{
CString sTemp;
sTemp.Format(_T("目录%s无法创建!"), path.m_strPath);
AfxMessageBox(sTemp);
return false;
}
}
CFileFind finder;
// 打开指定的文件夹进行搜索
BOOL bWorking = finder.FindFile(strSrcPath + "\\" + "*.*");
while(bWorking)
{
// 从当前目录搜索文件
bWorking = finder.FindNextFile();
CString strFileName = finder.GetFileName();
CString strSrc = strSrcPath + "\\" + strFileName;
CString strDst = strDstPath + "\\" + strFileName;
// 判断搜索到的是不是"."和".."目录
if(!finder.IsDots())
{
// 判断搜索到的目录是否是文件夹
if(finder.IsDirectory())
{
// 如果是文件夹的话,进行递归
if(!CopyDir(strSrc, strDst))
return false;
}
else
{
// 如果是文件,进行复制
if(!CopyFile(strSrc, strDst, FALSE))
return false;
}
}
}
return true;
}