使用windows API复制文件到指定目录

 

不知道为啥,在string后面必须要加 '\0';不然,有的 复制成功,有的 复制失败

string sFrom = currTemplatePart->GetPartPath() + currTemplatePart->GetpPartMain()->GetPartName();
sFrom += "\\*.*";
sFrom += '\0';
iDirection += '\0';
SHFILEOPSTRUCTA s = { 0 };
ZeroMemory(&s, sizeof(SHFILEOPSTRUCT));
s.hwnd = NULL;
s.wFunc = FO_COPY;           // 复制
s.fFlags = FOF_NO_UI;        // 不显示UI
s.pFrom = sFrom.c_str();     //必须有额外的'\0'结尾
s.pTo = iDirection.c_str();  //必须有额外的'\0'结尾
if (int iRet = SHFileOperationA(&s))
{
UF_print_syslog("复制失败!", true);
}

 

    std::string sfrom= "D:\\python\\";
    std::string iDirection = "D:\\1111111";
    //sfrom.push_back('\0');
    //iDirection.push_back('\0');

    SHFILEOPSTRUCTA s = { 0 };
    ZeroMemory(&s, sizeof(SHFILEOPSTRUCT));
    s.hwnd = NULL;
    s.wFunc = FO_COPY;  //           // 复制
    s.fFlags = FOF_NO_UI; //       // 不显示UI
    s.pFrom = sfrom.c_str(); //     //必须有额外的'\0'结尾
    s.pTo = iDirection.c_str(); //  //必须有额外的'\0'结尾
    if(int iRet = SHFileOperationA(&s))
    {
        cout<<"复制失败"<<endl;
    }
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值