我感觉这个方式想法比较新颖,让我想要记录一下
bool CDirListCtrl::DirectoryOperate(CString strSrcFilePath, CString strDesFilePath, UINT nOptionType)
{
BOOL bRet = FALSE; //
CFileFind finder;
BOOL bWorking = finder.FindFile(strSrcFilePath);
while(bWorking)
{
bWorking = finder.FindNextFile();
if(finder.IsDots()) //如果是 "."(当前目录)或者 ".."(上级目录)
{
continue;
}
CString strSubSrcPath = finder.GetFilePath(); //得到源文件路径
CString strSubDespath = strSubSrcPath;
strSrcFilePath.Replace("\\*.*",""); //递归时处理
strDesFilePath.Replace("\\*.*","");
strSubDespath.Replace(strSrcFilePath, strDesFilePath); //得到目标文件路径
if(finder.IsDirectory())
{
CreateDirectory(strSubDespath,NULL); //创建新的文件夹
bRet = DirectoryOperate(strSubSrcPath +"\\*.*" , strSubDespath +"\\*.*" , nOptionType); //递归
}
else
{
bRet = CopyFile(strSubSrcPath, strSubDespath, false); //拷贝文件
}
if (!bRet) break;
}
finder.Close();
return bRet;
}