MoveFileEx not delete file after reboot

458 Views Asked by At

Someone could explain why MoveFileEx on following code not delete files after reboot? thanks.

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.
0

There are 0 best solutions below