New Issue: Should we add replacement functions to the Path module?

16767, “e-kayrakli”, “Should we add replacement functions to the Path module?”, “2020-11-20T21:42:34Z”

The Path module has functions to make basic low-level transformations on files. However, there’s no function for replacing parts of a path string, and the user would have to use string functions (slice, concat etc) to achieve that.

Python’s os.path doesn’t have such functions, but higher-level pathlib does have some methods to call on Path objects: https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.with_name

I think we should add some replacement functions to the Path module. I suggest the following:

One design question about them would be what happens if the path doesn’t have dirname, basename, or extension. We can adopt pathlib’s naming scheme, e.g. withDirname, withBasename etc, that would add the given part if it doesn’t exist and replace if it does.