Copy Directory recursively and overwrite all files without user confirmation

Viewed 409

I have a simple function:

function CopyDir(const fromDir, toDir: string): Boolean;
var
  fos: TSHFileOpStruct;
begin
  ZeroMemory(@fos, SizeOf(fos));
  with fos do
  begin
    wFunc  := FO_COPY;
    fFlags := FOF_FILESONLY;
    pFrom  := PChar(fromDir + #0);
    pTo    := PChar(toDir)
  end;
  Result := (0 = ShFileOperation(fos));
end;

When I copy, a confirmation window pops up saying that a file already exists, asking if it should be overwritten.

I would like to avoid this popup and overwrite everything without confirmation.

1 Answers

Add flag FOF_NOCONFIRMATION to eliminate alerts

Related