Path.rename

void rename(string target) const

Renames or moves the file or directory represented by this Path to target.

Semantics follow Python's pathlib Path.rename() as closely as possible:

  • On POSIX, this uses rename(2) which is atomic and will overwrite the destination if it exists when the source and destination are on the same filesystem (see also replace).
  • On Windows, this maps to std.file.rename, which fails if the target exists. Use replace to ensure overwrite semantics.

    Parameters

    targetThe destination file or directory path.