diff --git a/stgpytools/types/file.py b/stgpytools/types/file.py index a96693f..ba03387 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', @@ -99,5 +101,10 @@ def write_lines( ) -> int: 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]