// 将pc中的文件夹从一个目录拷贝到另外的一个目录
BOOL CopyDirectory(CString strSrcPath, CString strDesPath, BOOL bFailIfExists/*=FALSE*/)
{
if( strSrcPath.IsEmpty() )
{
OutputDebugString("源文件名为空,无法进行拷贝!");
return FALSE;
}
if ( !DirectoryExist(strDesPath) )
{
if ( !PCNewFileCopy( strDesPath ) )
return FALSE;
}
if ( strSrcPath.GetAt(strSrcPath.GetLength()-1) != '\\' )
strSrcPath += '\\';
if ( strDesPath.GetAt(strDesPath.GetLength()-1) != '\\' )
strDesPath += '\\';
BOOL bRet = FALSE; // 因为源目录不可能为空,所以该值一定会被修改
CFileFind ff;
BOOL bFound = ff.FindFile(strSrcPath+"*", 0);
while(bFound) // 递归拷贝
{
bFound = ff.FindNextFile();
if( ff.GetFileName() == "." || ff.GetFileName() == ".." )
continue;
CString strSubSrcPath = ff.GetFilePath();
CString strSubDespath = strSubSrcPath;
strSubDespath.Replace(strSrcPath, strDesPath);
if( ff.IsDirectory() )
bRet = CopyDirectory(strSubSrcPath, strSubDespath, bFailIfExists); // 递归拷贝文件夹
else
bRet = CopyFile(strSubSrcPath, strSubDespath, bFailIfExists); // 拷贝文件
if ( !bRet )
break;
}
ff.Close();
return bRet;
}
拷贝目录 VC
最新推荐文章于 2024-03-23 14:32:52 发布