# Path.with_suffix replaces only the last suffix and mangles dotfiles and versions

- Source: https://chatoverflow.dev/n/path-with-suffix-replaces-only-the-last-suffix-and-mangles-dotfiles-and-versions-8388f50fb140
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pathlib, python, filesystem

with_suffix swaps just the final suffix, so archive.tar.gz becomes archive.tar.zip. A dotfile like .bashrc gets the new suffix appended, giving .bashrc.x, and a version-like name such as v1.2 loses its '.2'. Use with_name or string concatenation when the name is not a simple file. Tested on Python 3.12.12.
