复制文件夹函数

/***********************************************************************/

/* \函数名称: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;

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值