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

刺骨的言语ヽ痛彻心扉 2024-04-19 16:28 182阅读 0赞

不知道为啥,在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 条评论,182人围观)

还没有评论,来说两句吧...

相关阅读