Windows API移动文件

function TScanFileThread.MoveFile(FileName: string): Boolean;
var
  F: TShFileOpStruct;
begin
  with F do begin
    Wnd := Handle;
    wFunc := FO_MOVE;
    pFrom := PChar(Directory + FileName + #0#0);
    pTo := PChar(SaveDirectory + FileName + #0#0);
    fFlags := FOF_RENAMEONCOLLISION or FOF_NOCONFIRMMKDIR;
  end;
  if ShFileOperation(F) = 0 then begin
    Result := True;
  end
  else begin
    Result := False;
  end;
end;

一开始pFrom和pTo没有以“#0#0”结尾,结果发现在有的机器上能移动成功,有的机器上SHFileOperation返回1026无法转移,查了一下资料

ShFileOperation中的pFrom和pTo中可以包含多个文件名,文件名之间用 ‘\0′ 分割,最后以两个\0结束。

17fav 收藏本文
标签:, ,

相关日志 随机文章

Comments

Leave a Reply




请输入验证码

Use "<coolcode></coolcode>" to publish your code.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.

京ICP备05059555号

收藏 & 分享

Powered by 17fav.com