From 35c31252de56a9240331202f0ae8b972b8a6cb24 Mon Sep 17 00:00:00 2001 From: LightArrowsEXE Date: Mon, 3 Jun 2024 09:18:04 -0700 Subject: [PATCH] SPath: Add `append_to_stem` (#4) --- stgpytools/types/file.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stgpytools/types/file.py b/stgpytools/types/file.py index 9a1c261..2d86758 100644 --- a/stgpytools/types/file.py +++ b/stgpytools/types/file.py @@ -4,6 +4,8 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, TypeAlias, Union +from ..functions import to_arr + __all__ = [ 'FilePathType', 'FileDescriptor', 'FileOpener', @@ -113,5 +115,10 @@ def write_lines( return super().write_text('\n'.join(data), encoding, errors, newline) + def append_to_stem(self, suffixes: str | Iterable[str], sep: str = '_') -> SPath: + """Append a suffix to the stem of the path""" + + return self.with_stem(sep.join([self.stem, *to_arr(suffixes)])) # type:ignore[list-item] + SPathLike = Union[str, Path, SPath]