Path.withSuffix

Path withSuffix(string newSuffix) const @safe

Return a new Path with the last suffix (extension) replaced.

Modeled after pathlib's with_suffix:

  • newSuffix must be empty (to remove the last suffix) or start with a dot (e.g., ".md").
  • If there is no suffix and newSuffix is non-empty, it is appended to the name.
  • Only the last suffix is affected; earlier suffixes (e.g., ".tar" in "archive.tar.gz") remain part of the stem.
  • Dotfiles without additional dots (e.g., ".bashrc") are treated as having no suffix; in that case withSuffix(".txt") yields ".bashrc.txt".

    Parameters

    newSuffixThe new file suffix. Must start with a dot or be empty.

    Returns

    A new Path with the last suffix replaced accordingly.