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
🌐
PyTutorial
pytutorial.com › python-pathlibstem-explained-file-path-manipulation
PyTutorial | Python Pathlib.stem Explained | File Path Manipulation
March 23, 2025 - For example, you can use with_suffix() to change the file extension after extracting the stem. ... from pathlib import Path # Create a Path object file_path = Path("/documents/report.txt") # Change the suffix new_path = file_path.with_suffix(".pdf") print(new_path) ... This code changes the file extension from .txt to .pdf. Learn more about Python Pathlib with_suffix().
🌐
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.
🌐
NHS Digital
nhsdigital.github.io › rap-community-of-practice › training_resources › python › handling-file-paths
Handling file paths - RAP Community of Practice
August 21, 2026 - # Note: __file__ is a global Python variable this_file_path = pathlib.Path(__file__) print("Path to file:", this_file_path) print("File name:", this_file_path.name) print("File stem:", this_file_path.stem) print("Parent folder:", this_file_path.parent) To see all the options (there are many!) use help(pathlib.Path) or see the pathlib-docs.
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
4 days ago - When using .write_text(), Python overwrites any existing files on the same path without giving you any notice. That means you could erase all your hard work with a single keystroke! As always, when you write files with Python, you should be cautious of what your code is doing. The same is true when you’re renaming files. ... When you want to rename files, you can use .with_stem(), .with_suffix(), or .with_name().
🌐
pythontutorials
pythontutorials.net › blog › clean-way-to-get-the-true-stem-of-a-path-object
How to Get the 'True' Stem of a Path Object Cleanly in Python (Even Without Suffixes) — pythontutorials.net
Let’s explore four methods to extract the true stem, each with tradeoffs in simplicity, flexibility, and edge-case handling. For filenames with one suffix, pathlib provides with_suffix(''), which returns a new path with the last suffix removed.
🌐
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 stem returns the file name without the extension. Working with the stem can be useful when converting files to different formats. ... Note: On a Mac, file paths are case-sensitive, so /Users/username/Documents and /users/username/documents ...
🌐
Miguendes
miguendes.me › python-pathlib
Python pathlib Cookbook: 57+ Examples to Master It (2022)
July 2, 2022 - >>> from pathlib import Path >>> picture = Path('/home/miguel/Desktop/profile.png') >>> picture.stem 'profile'
Find elsewhere
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
>>> 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.
🌐
Basicexamples
basicexamples.com › example › python › pathlib-purepath-stem
Basic example of Python function pathlib.PurePath.stem
python · pathlib · purepath · from pathlib import PurePath path = PurePath("/path/to/file.txt") stem = path.stem print(stem) path manipulation · python · pathlib · purepath · file handling · python · pathlib · purepath · file handling ·
🌐
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.
🌐
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): ...
🌐
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'] W…
🌐
ZetCode
zetcode.com › python › pathlib
Python pathlib - working with files and directories in Python with pathlib
January 29, 2024 - Python pathlib tutorial shows how to work with files and directories in Python with pathlib module.
🌐
Runebook.dev
runebook.dev › en › docs › python › library › pathlib › pathlib.PurePath.stem
python - Beyond the Extension: A Guide to pathlib.stem
Here is an explanation of common troubles and alternative methods for using PurePath. stem, complete with example code.The stem property of a PurePath object gives you the final path component's name without its suffix (file extension)
🌐
GeeksforGeeks
geeksforgeeks.org › python › pathlib-module-in-python
Pathlib Module in Python - GeeksforGeeks
1. Path class: It represents a path and allows for a variety of methods that interact directly with the filesystem. Depending on system Python is running on, Path will behave like either PosixPath or WindowsPath.
Published: June 15, 2026
🌐
Runebook.dev
runebook.dev › en › docs › python › library › pathlib › pathlib.PurePath.with_stem
PurePath's Power: A Deep Dive into with_stem() for Python Developers
PurePath.with_stem(stem) is a method that creates a new path object with the stem changed, but keeps the rest of the path intact, including the parent directory and the file extension (suffix).
🌐
Iditect
iditect.com › faq › python › clean-way-to-get-the-quottruequot-stem-of-a-path-object-in-python.html
Clean way to get the "true" stem of a Path object in python?
In Python, if you want to obtain the "true" stem of a Path object (the stem without any file extension), you can use the stem attribute provided by the pathlib module.