Path.expandUser

Path expandUser() const

Expands a leading tilde in the path to the user's home directory, similar to Python's os.path.expanduser / pathlib.Path.expanduser semantics.

Platform semantics:

  • POSIX:
  • `~` or `~/...` expands to the current user's home directory (prefers $HOME).
  • ~user or ~user/... expands to the named user's home directory via passwd.

If the user does not exist, the path is returned unchanged.

  • Windows:
  • `~` or `~\\...` or `~/...` expands to the current user's profile directory.
  • ~user is not supported and the path is returned unchanged (matches Python behavior).

Returns

A new Path with tilde expansion applied; if not applicable, returns this.