0

有人可以解释为什么MoveFileEx在以下代码中重新启动后不删除文件?谢谢。

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Winapi.Windows,
  System.SysUtils;

var
  FileName: array[0..128] of Char;
  FileNameZip: string;

begin
  try
    GetModuleFileName(HInstance, FileName, 128);
    FileNameZip := IncludeTrailingPathDelimiter(GetEnvironmentVariable('USERPROFILE') + '\Downloads') + ChangeFileExt(ExtractFilename(FileName), '.zip');

    Writeln(FileName);
    Writeln(FileNameZip);

    if not MoveFileEx(FileName, nil, MOVEFILE_DELAY_UNTIL_REBOOT) then
      SysErrorMessage(GetLastError);

    if not MoveFileEx(PWideChar(FileNameZip), nil, MOVEFILE_DELAY_UNTIL_REBOOT) then
      SysErrorMessage(GetLastError);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.
4

0 回答 0