Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用SHFILEOPSTRUCT和SHFileOperation时出现问题_C++ - Fatal编程技术网

C++ 使用SHFILEOPSTRUCT和SHFileOperation时出现问题

C++ 使用SHFILEOPSTRUCT和SHFileOperation时出现问题,c++,C++,我正在尝试使用该功能将文件夹从一个目录复制到另一个目录 我使用此链接编写了以下代码: 但我得到了错误代码0x7B,当我搜索有关错误的信息时,显示:“文件名、目录名或卷标语法不正确。” 我正确写入了文件名和目录名,但我不知道为什么此代码无法将ty文件夹从D驱动器复制到D驱动器上另一个名为secondfolder的文件夹 对不起,我在你的网站上搜索了很多,但是我没有得到任何关于我的问题的答案 #include <iostream> #include <Windows.h>

我正在尝试使用该功能将文件夹从一个目录复制到另一个目录

我使用此链接编写了以下代码:

但我得到了错误代码0x7B,当我搜索有关错误的信息时,显示:“文件名、目录名或卷标语法不正确。”

我正确写入了文件名和目录名,但我不知道为什么此代码无法将
ty
文件夹从D驱动器复制到D驱动器上另一个名为
secondfolder
的文件夹

对不起,我在你的网站上搜索了很多,但是我没有得到任何关于我的问题的答案

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
    system("color 0A")
    SHFILEOPSTRUCT fo;
    memset(&fo, 0, sizeof(fo));
    fo.hwnd = 0;
    fo.wFunc = FO_COPY;
    fo.pFrom = L"D:\\ty\\*\0";
    fo.pTo = L"D:\\secondfolder\\*\0";
    fo.fFlags = FOF_NOCONFIRMMKDIR |
        FOF_NOCONFIRMATION |
        FOF_NOERRORUI |
        FOF_SILENT;
    int n = SHFileOperation(&fo);
    if(n == 0)
    {
        cout << "success" << endl;
    }
    else if (n != 0)
    {
        cout << "faild" << endl;
        cout << hex << n << endl;
    }

    system("PAUSE");
    return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
系统(“颜色0A”)
SHFILEOPSTRUCT-fo;
memset(&fo,0,sizeof(fo));
fo.hwnd=0;
fo.wFunc=fo_副本;
fo.pFrom=L“D:\\ty\\\*\0”;
fo.pTo=L“D:\\secondfolder\\*\0”;
fo.fFlags=FOF_noconfirmkdir|
确认|
福乌·诺埃罗瑞|
FOF_沉默;
int n=SHFileOperation(&fo);
如果(n==0)
{

您是否需要从
pTo
中删除
*

fo.pTo = L"D:\\secondfolder\\\0";
此外,您正在尝试仅复制
ty
的内容,而不是复制
ty
本身。如果需要,请从
pFrom
中删除
*

fo.pFrom = L"D:\\ty\\\0";

@AlexF阅读了文档。
pTo
pFrom
上需要额外的空终止符,因为它们是双空终止列表。
fo.pFrom=L“D:\\ty\\\*\0;fo.pTo=L“D:\\secondfolder\\\\0”