- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试将目录复制到新位置。所以我使用 SHFileOperation/SHFILEOPSTRUCT 如下:
SHFILEOPSTRUCT sf;
memset(&sf,0,sizeof(sf));
sf.hwnd = 0;
sf.wFunc = FO_COPY;
dirName += "\\*.*";
sf.pFrom = dirName.c_str();
string copyDir = homeDir + "\\CopyDir";
sf.pTo = copyDir.c_str();
sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI;
int n = SHFileOperation(&sf);
if(n != 0)
{
int x = 0;
}
所以我设置了上面的值。文件夹中有一个我创建的文件(我已经关闭了 handle ,所以应该可以移动)。 SHFileOperation 调用返回 2,但我找不到解释这些错误代码的任何地方。有谁知道我在哪里可以找到 2 的意思,或者有谁知道为什么它可能不起作用?干杯
最佳答案
错误代码 2 表示系统找不到指定的文件。
参见 Windows System Error Codes获取错误描述的完整列表,或编写一个函数来获取错误代码的描述:
std::string error_to_string(const DWORD a_error_code)
{
// Get the last windows error message.
char msg_buf[1025] = { 0 };
// Get the error message for our os code.
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
0,
a_error_code,
0,
msg_buf,
sizeof(msg_buf) - 1,
0))
{
// Remove trailing newline character.
char* nl_ptr = 0;
if (0 != (nl_ptr = strchr(msg_buf, '\n')))
{
*nl_ptr = '\0';
}
if (0 != (nl_ptr = strchr(msg_buf, '\r')))
{
*nl_ptr = '\0';
}
return std::string(msg_buf);
}
return std::string("Failed to get error message");
}
来自阅读 SHFileOperation 的文档为 pTo
和 pFrom
指定的字符串必须是双空终止的:你的只是单空终止的。尝试以下操作:
dirName.append(1, '\0');
sf.pFrom = dirName.c_str();
string copyDir = homeDir + "\\CopyDir";
copyDir.append(1, '\0');
sf.pTo = copyDir.c_str();
关于c++ - SHFileOperation/SHFILEOPSTRUCT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9191415/
这个旧的 C++ 函数适用于 32 位操作系统,但不适用于 64 位操作系统。我想复制文件夹。你知道我必须改变什么吗? ************** Exception Text ******
我正在尝试使用 SHFileOperation 将文件从一个位置复制到另一个位置: SHFILEOPSTRUCT fileop; fileop.hwnd = 0; fileop.wFunc = FO_
我正在尝试将目录复制到新位置。所以我使用 SHFileOperation/SHFILEOPSTRUCT 如下: SHFILEOPSTRUCT sf; memset(&sf,0,sizeof(sf));
我正在为 WiX 编写一个 C++ 自定义操作,它将在安装期间调用以删除安装程序安装的任何残留物。考虑以下代码: UINT __stdcall DeleteResidue(MSIHANDLE hIns
我正在尝试通过 SHFileOperationA 复制文件夹功能。这是我的代码。 int main() { SHFILEOPSTRUCTA sf; int result; s
我正在使用 SHFileOperation() 从特定路径删除目录。它是在多个线程中完成的,删除的目录总是不同的。 有时,它会抛出异常: Exception thrown at 0x00007FF8A
我想要 一个后台线程将通过 SHFileOperation 函数复制文件,一次始终只有一个 SHFileOperation (但我希望它位于线程中)< 我需要 UI 输出,因此需要使用 FOF_SIM
我正在使用以下代码删除大量文件 function FastDelete(const fromDir: string): Boolean; var fos: TSHFileOpStruct; beg
我正在使用 Shell API 复制包含文件的文件夹。 SHFILEOPSTRUCT sf = {0}; sf.wFunc = FO_COPY; sf.hwnd = 0; sf.fFlags = FO
我正在尝试编写一个程序,该程序将使用 Windows API 根据日期删除一组与特定命名模式(通配符)匹配的文件/文件夹 ... SHFILEOPSTRUCT shFileOpStruct =
我有一段代码使用带有 FO_MOVE 操作的 Windows SHFileOperation 函数。指定的其他标志是 FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_
我使用这个程序: function MoveToRecycle(sFileName: widestring): Boolean; var fos: TSHFileOpStructW; begin
我有一个基于 MDI 的框架应用程序正在调用 SHFileOperation,如下所示: SHFILEOPSTRUCT opDelFiles = {0}; opDelFiles.hwnd = AfxG
我想删除一个文件到回收站。我使用这段代码。 SHFILEOPSTRUCT FileOp; FileOp.hwnd = NULL; FileOp.wFunc=FO_DELETE;
我正在使用以下函数将文件删除到回收站:(C++、MFC、Unicode) bool DeleteFileToPaperbasket (CString filename) { TCHAR Buff
我正在尝试将 A 驱动器的内容复制到文件夹 C:\test\disk1 中。文件夹 disk1 已经存在。该程序编译但运行时出现错误 87。我知道错误 87 与无效参数有关,但我不确定问题出在哪里。有
我找到了一些使用 SHFileOperation() 复制文件的代码,但我对 SHFILEOPSTRUCT structure 中可用的所有标志感到困惑. 这就是我正在做的事情。我有一个递归过程,根据
这会在桌面上创建一个新文件夹,但不会将文件夹 .pfrom 的内容 move 到文件夹 .pTo。 int main() { SHFILEOPSTRUCT sf = {0}; TCHA
我有一个涉及 SHFileOperation 的问题: SHFILEOPSTRUCT sf2; memset(&sf2,0,sizeof(sf2)); sf2.hwnd = N
我正在尝试使用 SHFileOperation 将文件/目录从一个位置复制到另一个位置。到目前为止,我的代码是, for(int index=0; index < clbSource.GetC
我是一名优秀的程序员,十分优秀!