PurePath.withName() method
pathlib-ts > PurePath > withName
PurePath.withName() method
Section titled “PurePath.withName() method”Returns a new path with the final component replaced by the provided name.
Signature:
withName(name: string): PurePath;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
name |
string |
Replacement leaf component. Must not contain path separators. |
Returns:
A new path with the same anchor and parent but a different final component.
Exceptions
Section titled “Exceptions”The Error class If the name is empty, . or contains separators.
Remarks
Section titled “Remarks”Input validation mirrors CPython: path separators and empty names are rejected. Use this when you need to replace the leaf node while keeping the same directory.