Path.replace

void replace(string target) const

Overwrites target by moving this path over it. On platforms that support it (POSIX), this is an atomic replacement using rename(2).

Platform semantics:

  • POSIX: Uses rename(2) which atomically replaces target if it exists.
  • Windows: Uses MoveFileExW with MOVEFILE_REPLACE_EXISTING, replacing the destination atomically and never deleting it manually — a failed move leaves the destination untouched.

This mirrors Python's pathlib Path.replace() behavior.

Parameters

targetThe destination path to be replaced by this path.

Throws

NotFoundError if this path does not exist; PathError

(or a subclass) when the underlying move fails.