Return a new path with the file name changed.
(self, name)
| 406 | return tail[-1] |
| 407 | |
| 408 | def with_name(self, name): |
| 409 | """Return a new path with the file name changed.""" |
| 410 | p = self.parser |
| 411 | if not name or p.sep in name or (p.altsep and p.altsep in name) or name == '.': |
| 412 | raise ValueError(f"Invalid name {name!r}") |
| 413 | tail = self._tail.copy() |
| 414 | if not tail: |
| 415 | raise ValueError(f"{self!r} has an empty name") |
| 416 | tail[-1] = name |
| 417 | return self._from_parsed_parts(self.drive, self.root, tail) |
| 418 | |
| 419 | def with_stem(self, stem): |
| 420 | """Return a new path with the stem changed.""" |