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
To access the individual “parts” (components) of a path, use the following property: ... >>> p = PurePath('/usr/bin/python3') >>> p.parts ('/', 'usr', 'bin', 'python3') >>> p = PureWindowsPath('c:/Program Files/PSF') >>> p.parts ('c:\\', 'Program Files', 'PSF') (note how the drive and local root are regrouped in a single part) The parent, name, stem, and suffix properties describe different parts of a path.
Discussions

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
November 7, 2024
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 is cool

Its awesome, I love the read/write_text/bytes functions so convenient!

More on reddit.com
🌐 r/Python
196
483
July 28, 2022
🌐
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…
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
1 day 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().
🌐
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 - In addition to the with_stem() function to rename a file's stem, pathlib offers the rename() method to rename more completely.
🌐
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.
Find elsewhere
🌐
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)
🌐
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 ·
🌐
Medium
medium.com › aiadventures › file-paths-file-systems-90474a2e5461
File paths & file systems. I recently had few problems with paths… | by Shyam Rathod | aiadventures | Medium
March 16, 2021 - .stem: the file name without the suffix · .suffix: the file extension · Path.cwd() / ‘python’ / ‘scripts’ / ‘movie.csv’ · A simple way to open a file is simply to use folder names and filename.
🌐
GeeksforGeeks
geeksforgeeks.org › python › get-filename-from-path-without-extension-using-python
Get filename from path without extension using Python - GeeksforGeeks
October 3, 2025 - Python · import pathlib path = 'D:\\home\\Riot Games\\VALORANT\\live\\VALORANT.exe' name = pathlib.Path(path).stem print(name) Output: VALORANT · Explanation: Path(path).stem returns the filename minus its extension.
🌐
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
🌐
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): ...
🌐
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 ...
Author: python
🌐
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.