c++ 复制文件夹及其内所有子文件内容

来源:互联网 发布:剑三好看的纯阳脸数据 编辑:程序博客网 时间:2024/05/16 04:33
BOOL CopyDirectoryAllFiles(CString srcDir,CString destDir )
{
if( srcDir.IsEmpty() || destDir.IsEmpty() )return FALSE;
CFileFind ff;
BOOL bFind = ff.FindFile(srcDir + _T("\\*"));
CString newFilePath;
while( bFind )
{
bFind = ff.FindNextFile();
if( !ff.IsDirectory() )
{
newFilePath = destDir + _T("\\");
newFilePath += ff.GetFileName();
if( !::CopyFile(ff.GetFilePath(),newFilePath,FALSE) )
return FALSE;
}
}
return TRUE;
}




BOOL CopyDirecotryName(CString srcDir,CString destDir)
{
if( srcDir.IsEmpty() || destDir.IsEmpty() )
{
return FALSE;
}
CFileFind  ff;
BOOL bFind = ff.FindFile(srcDir+ _T("\\*"));
CString srcPath, destPath;
while( bFind )
{
bFind = ff.FindNextFile();
if( (ff.GetFileName() == _T(".") || ff.GetFileName() == _T("..")))
continue;
if( ff.IsDirectory())
{
destPath = destDir + _T("\\");
destPath += ff.GetFileName();
srcPath = ff.GetFilePath();
::CreateDirectory(destPath,NULL);
CopyDirectoryAllFiles(srcDir,destDir);
CopyDirecotryName(srcPath,destPath);
CopyDirectoryAllFiles(srcPath,destPath);
}


}
return TRUE;
}
0 0
原创粉丝点击