You could just .split it:

>>> Path('logs/date.log.txt').stem.split('.')[0]
'date'

os.path works just as well:

>>> os.path.basename('logs/date.log.txt').split('.')[0]
'date'

It passes all of the tests:

In [11]: all(Path(k).stem.split('.')[0] == v for k, v in {
   ....:     'a': 'a',
   ....:     'a.txt': 'a',
   ....:     'archive.tar.gz': 'archive',
   ....:     'directory/file': 'file',
   ....:     'd.x.y.z/f.a.b.c': 'f',
   ....:     'logs/date.log.txt': 'date'
   ....: }.items())
Out[11]: True
Answer from Blender on Stack Overflow
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
February 23, 2026 - >>> PurePosixPath('my/library.tar.gz').stem 'library.tar' >>> PurePosixPath('my/library.tar').stem 'library' >>> PurePosixPath('my/library').stem 'library' Changed in version 3.14: A single dot (”.”) is considered a valid suffix. ... Return whether the path is absolute or not.
Discussions

python - Pathlib and stem - Attributerror - Stack Overflow
path.with_stem() was introduced in Python 3.9. More on stackoverflow.com
🌐 stackoverflow.com
`pathlib.PurePath.with_stem('')` promotes file extension to stem
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ... The with_stem() call should raise ValueError, as it's impossible ... More on github.com
🌐 github.com
0
January 26, 2024
pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot
3.14bugs and security fixesbugs ... Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ... Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state. ... assignee = None closed_at = None created_at = labels = ['3.8', 'type-bug', 'library'] title = 'pathlib .suffix, .suffixes, .stem unexpected ... More on github.com
🌐 github.com
7
October 28, 2019
add setter for pathlib.stem
Feature or enhancement Proposal: It would be nice to have the option to modify the stem of a file name directly. Say I have a Path '/tmp/myfile.npy': file_path = Path('/tmp/myfile.npy&#... More on github.com
🌐 github.com
3
November 7, 2024
🌐
Python.org
discuss.python.org › ideas
Add pathlib.Path.stems - Ideas - Discussions on Python.org
April 20, 2023 - Path.suffix is to Path.stem as Path.suffixes is to …? >>> from pathlib import Path >>> p = Path("CurveFile.vs2022.vcxproj") >>> p.suffix '.vcxproj' >>> p.stem 'CurveFile.vs2022' >>> p.suffixes ['.vs2022', '.vcxproj'] While you can programmatically get each and every suffix, currently, there ...
🌐
DataCamp
datacamp.com › tutorial › comprehensive-tutorial-on-using-pathlib-in-python-for-file-system-manipulation
How to Use Python's Pathlib (with Examples) | DataCamp
May 22, 2024 - The with_stem() method returns a file path with a different filename (although the suffix stays the same).
🌐
OneUptime
oneuptime.com › home › blog › how to use pathlib for file paths in python
How to Use pathlib for File Paths in Python
January 27, 2026 - # path_components.py # Accessing different parts of a path from pathlib import Path path = Path("/home/user/project/data/report.csv.gz") # Name - final component print(f"Name: {path.name}") # report.csv.gz # Stem - name without final suffix print(f"Stem: {path.stem}") # report.csv # Suffix - final extension print(f"Suffix: {path.suffix}") # .gz # Suffixes - all extensions print(f"Suffixes: {path.suffixes}") # ['.csv', '.gz'] # Parent - immediate parent directory print(f"Parent: {path.parent}") # /home/user/project/data # Parents - all ancestor directories for parent in path.parents: print(f" {
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
January 11, 2025 - You’re using .with_stem() to create the new filename without changing the extension. The actual copying takes place in the highlighted line, where you use .read_bytes() to read the content of source and then write this content to destination using .write_bytes(). While it’s tempting to use pathlib for everything path related, you may also consider using shutil for copying files.
🌐
Python Morsels
pythonmorsels.com › pathlib-module
Python's pathlib module - Python Morsels
November 18, 2024 - Python's pathlib module is the tool to use for working with file paths. See pathlib quick reference tables and examples.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-pathlib-module-in-python
Python Path – How to Use the Pathlib Module with Examples
May 10, 2022 - In [*]: p = pathlib.PurePath('/src/goo/scripts/main') p.with_suffix('') Out[*]: PurePosixPath('/src/goo/scripts/main') Some methods like .with_stem(), and .is_relative_to() have been added recently to Python 3.9 and above.
🌐
Mopicmp
mopicmp.github.io › python-pathlib › path-stem.html
Path.stem - Python Pathlib | BetterDocs
for filepath in output_dir.glob("*.lua"): if filepath.name.endswith(".meta"): continue # Filename format: owner__name.lua stem = filepath.stem if "__" in stem: owner, name = stem.split("__", 1) cached.add(f"{owner}/{name}") return cached def fetch_configs( self, query: str = "filename:init.lua path:nvim", max_repos: int = 500, progress_callback=None, ) -> Iterator[ConfigFile]: """ Fetch Neovim configurations from GitHub.
🌐
GitHub
github.com › python › cpython › issues › 114610
`pathlib.PurePath.with_stem('')` promotes file extension to stem · Issue #114610 · python/cpython
January 26, 2024 - 3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ... The with_stem() call should raise ValueError, as it's impossible for a filename to have an empty stem and a non-empty suffix.
Author   barneygale
🌐
Readthedocs
autoclasstoc.readthedocs.io › en › latest › examples › pathlib.html
pathlib.Path — autoclasstoc 1.7.0 documentation
The snippet below shows how autoclasstoc can be used to document the pathlib.Path class from the Python standard library. This example also includes inheritance.
🌐
GitHub
github.com › python › cpython › issues › 82805
pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot · Issue #82805 · python/cpython
October 28, 2019 - 3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ... Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state. ... assignee = None closed_at = None created_at = <Date 2019-10-28.22:54:26.232> labels = ['3.8', 'type-bug', 'library'] title = 'pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot' updated_at = <Date 2019-10-29.01:59:29.319> user = 'https://bugs.python.org/inyeollee'
Author   inyeollee
🌐
Stack Abuse
stackabuse.com › introduction-to-the-python-pathlib-module
Introduction to the Python Pathlib Module
August 7, 2023 - stem: final path component without its suffix · suffix: the file extension of the final component · anchor: the part of a path before the directory. / is used to create child paths and mimics the behavior of os.path.join. joinpath: combines the path with the arguments provided · match(pattern): ...
🌐
Astral
docs.astral.sh › ruff › rules › os-path-splitext
os-path-splitext (PTH122) | Ruff
from pathlib import Path path = Path("foo/bar.py") root = path.parent / path.stem ext = path.suffix · While using pathlib can improve the readability and type safety of your code, it can be less performant than the lower-level alternatives that work directly with strings, especially on older versions of Python.
🌐
PyTutorial
pytutorial.com › python-pathlibstem-explained-file-path-manipulation
PyTutorial | Python Pathlib.stem Explained | File Path Manipulation
March 23, 2025 - Learn how to use Python's pathlib.stem method to extract file names without extensions. Perfect for beginners in file path manipulation.
🌐
Python Tutorial
pythontutorial.net › home › python standard library › python path
Python Path: Interact with File System Using Path from pathlib
March 27, 2025 - from pathlib import Path path = Path('readme.txt') print(path.name)Code language: Python (python) Output: readme.txtCode language: Python (python) To get the file name without extension, you use the stem property: from pathlib import Path path = Path('readme.txt') print(path.stem)Code language: ...
🌐
GitHub
github.com › python › cpython › issues › 126537
add setter for pathlib.stem · Issue #126537 · python/cpython
November 7, 2024 - It would be nice to have the option to modify the stem of a file name directly. ... if the file exists, I want to change the file name to '/tmp/myfile-1.npy', in order to avoid overwriting it, I currently need to do the following: if file_path.exists(): file_path = file_path.parents / (file_path.stem + '-1' + file_path.suffix)
Author   thawn
🌐
IONOS
ionos.com › digital guide › websites › web development › python pathlib
How does Python pathlib work and what are its benefits?
June 18, 2025 - .parent: Refers to the directory con­tain­ing the file; if the path points to a directory, it returns the parent directory · .stem: Refers to the file name excluding the extension ...