简体   繁体   English

移动文件夹Windows C ++:Vista和更高版本,而不是XP

[英]Moving Folder Windows C++: Works Vista and up, not XP

I've been working on getting this right for a few hours now, and it works perfectly on Windows Vista & Windows 7, but when I run it on Windows XP it fails without any message. 我一直在努力现在得到这个正确的几个小时,和它完美的作品在Windows Vista和Windows 7,但是当我在Windows XP上运行失败,没有任何消息。 Unfortunately I don't have a development environment under XP so I can't just run it through a debugger to check, have I missed something blindingly obvious? 不幸的是我没有XP下的开发环境,所以我不能通过调试器运行它来检查,我是否错过了一些令人眼花缭乱的事情? The same piece of code does actually use a CopyFile and a few commands to write out data to C:\\ so if it's a permissions error it's an odd one. 同一段代码实际上使用CopyFile和一些命令将数据写出到C:\\所以如果它是权限错误则是一个奇怪的错误。

EDIT: The return value is 1223, ERROR_CANCELLED which means cancelled by user. 编辑:返回值为1223, ERROR_CANCELLED表示已被用户取消。

EDIT 2: I disabled the s.fFlags and it immediately popped a dialog box up asking if it should create the dir-test folder, so I switched to FOF_NOCONFIRMATION and it appeared to ignore the flag. 编辑2:我禁用了s.fFlags并立即弹出一个对话框询问是否应该创建dir-test文件夹,所以我切换到FOF_NOCONFIRMATION并且它似乎忽略了该标志。 I do also use that during a deletion using the same SHFileOperation method so it either doesn't apply to file copies. 我也使用相同的SHFileOperation方法在删除期间使用它,因此它不适用于文件副本。

LPTSTR source = L"dir-test\\*\0";               
LPTSTR dest = L"C:\\dir-test\0";


SHFILEOPSTRUCT s = { 0 };
s.hwnd = 0;
s.wFunc = FO_COPY;
s.fFlags = FOF_SILENT;
s.pTo = dest;
s.pFrom = source;
int n;
n = SHFileOperation(&s);`

So it turns out for some odd reason that using the SHFileOperation will force a confirm dialog for Windows XP (but not Vista or 7) and ignore the flags to tell it to just confirm. 因此,有一个奇怪的原因,使用SHFileOperation将强制Windows XP的确认对话框(但不是Vista或7)并忽略标志告诉它只是确认。 Simple fix of using CreateDirectory() prior to running the copy, which doesn't require a confirmation dialog. 在运行副本之前使用CreateDirectory()简单修复,不需要确认对话框。

The documentation for SHFILEOPSTRUCT has this warning: SHFILEOPSTRUCT的文档有此警告:

It cannot be overstated that your paths should always be full paths. 您的路径应始终是完整路径,这一点不容小觑。 If the pFrom or pTo members are unqualified names, the current directories are taken from the global current drive and directory settings as managed by the GetCurrentDirectory and SetCurrentDirectory functions. 如果pFrom或pTo成员是非限定名称,则当前目录将取自GetCurrentDirectory和SetCurrentDirectory函数管理的全局当前驱动器和目录设置。

Your source specification is an unqualified name. 您的source规范是不合格的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM