拷贝目录 VC

// 将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;
}


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值