找到你要的答案

Q:SHFileOperation returns 1223, only on xp

Q:SHFileOperation返回1223,只有在XP

I have a little console application to copy all files from one usb drive to another:

void CopyAllFiles(wchar_t** source, wchar_t* destination)
{
    WCHAR src[MAX_PATH + 1], dest[MAX_PATH + 1];
    wsprintf(src, L"%s*\0", *source);
    src[wcslen(src) + 1] = 0;             \\Just to be sure it ends with "\0\0"
    wsprintf(dest, L"%s\0", destination);
    dest[wcslen(dest) + 1] = 0;

    cout << "Source: " << src << endl << "Destination: " << dest << endl;

    SHFILEOPSTRUCT s = { 0 };
    s.hwnd = nullptr;
    s.wFunc = FO_COPY;
    s.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_NOCOPYSECURITYATTRIBS | FOF_RENAMEONCOLLISION | ;
    s.pTo = dest;
    s.pFrom = src;
    cerr << "SHFileOperation returns " << SHFileOperation(&s) << endl;
}

This works great on Windows 8.1, but when I try to run it on WinXP with same configuration, SHFileOperation returns 1223. I try to copy 1GB from 4GB USB to empty 64GB USB.

Any idea why this happens?

我有一个小小的控制台应用程序的所有文件复制到另一个从一个USB驱动器:

void CopyAllFiles(wchar_t** source, wchar_t* destination)
{
    WCHAR src[MAX_PATH + 1], dest[MAX_PATH + 1];
    wsprintf(src, L"%s*\0", *source);
    src[wcslen(src) + 1] = 0;             \\Just to be sure it ends with "\0\0"
    wsprintf(dest, L"%s\0", destination);
    dest[wcslen(dest) + 1] = 0;

    cout << "Source: " << src << endl << "Destination: " << dest << endl;

    SHFILEOPSTRUCT s = { 0 };
    s.hwnd = nullptr;
    s.wFunc = FO_COPY;
    s.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_NOCOPYSECURITYATTRIBS | FOF_RENAMEONCOLLISION | ;
    s.pTo = dest;
    s.pFrom = src;
    cerr << "SHFileOperation returns " << SHFileOperation(&s) << endl;
}

这个伟大的作品在Windows 8.1,但是当我尝试同配置WinXP运行它,SHFileOperation函数返回1223。我试图复制1GB起4GB USB空64GB的通缉USB。

知道为什么会这样吗?

answer1: 回答1:

Ok, I didn't realize I have to specify path to existing directory - on Win8 it automatically creates the directory, on xp it doesn't.

Big thanks to all of you guys for help and suggestions.

好吧,我不知道我要指定路径到现有目录- Win8自动创建目录,XP不行。

非常感谢大家的帮助和建议。

c++  windows  winapi  windows-xp