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
The stem excludes only the final suffix: in this example, it includes .tar. Pure paths provide the following methods and properties:
Discussions

Add pathlib.Path.stems - Ideas - Discussions on Python.org
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 ... More on discuss.python.org
🌐 discuss.python.org
2
April 20, 2023
`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
python - Pathlib and stem - Attributerror - Stack Overflow
I am very new to Pathlib and stem, someone smarter than me recommended that I look into it so apologize if the question sounds newbie ... Yes you're right, version issue. Mine is 3.8... Do you have any solution/replacement for older version? ... Save this answer. ... Show activity on this post. path.with_stem() was introduced in Python ... More on stackoverflow.com
🌐 stackoverflow.com
How to get only the name of the path with python? - Stack Overflow
In Python 3.4 or newer (or as a separate backport install), you can also use the pathlib library, which offers a more object-oriented approach to path handling. pathlib.Path() objects have a .stem attribute, which is the final component without the extension suffix: More on stackoverflow.com
🌐 stackoverflow.com
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
4 days ago - On older versions of Python, Path doesn’t have a method to copy files. But with the knowledge that you’ve gained about pathlib so far, you can create the same functionality with a few lines of code: ... >>> from pathlib import Path >>> source = Path("shopping_list.md") >>> destination = source.with_stem("shopping_list_02") >>> destination.write_bytes(source.read_bytes())
🌐
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…
🌐
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" {
Author: python
Find elsewhere
🌐
ZetCode
zetcode.com › python › pathlib
Python pathlib - working with files and directories in Python with pathlib
January 29, 2024 - $ parts2.py The stem is: wordpress-5.1.tar The name is: wordpress-5.1.tar.gz The suffix is: .gz The anchor is: C:\ File name: wordpress-5.1 The suffixes: ['.1', '.tar', '.gz'] The iterdir yields path objects of the directory contents. ... #!/usr/bin/python from pathlib import Path path = Path('C:/Users/Jano/Documents') dirs = [e for e in path.iterdir() if e.is_dir()] print(dirs)
🌐
Runebook.dev
runebook.dev › en › docs › python › library › pathlib › pathlib.PurePath.stem
python - Beyond the Extension: A Guide to pathlib.stem
When the path points to a directory or a path component without a suffix, stem returns the full name of the last component, which is the same as the name property. You might expect an error or a different output if a path doesn't look like a ...
🌐
Miguendes
miguendes.me › python-pathlib
Python pathlib Cookbook: 57+ Examples to Master It (2022)
July 2, 2022 - A natural way of doing this would be splitting the string on the dot. However, pathlib.Path comes with another helper property named Path.stem, which returns the final component of the path, without the extension.
🌐
Medium
dzdata.medium.com › pathlib-a-better-way-to-work-with-paths-in-python-4f24dea14fab
pathlib — a Better Way to Work with Paths in Python | by Dor Zvulun | Medium
July 19, 2023 - new_name_path = path_to_my_file.with_stem('new_file') path_to_my_file.rename(new_name_path) ... The pathlib module is a powerful tool to handle paths, files, and directories.
🌐
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
If you use with_stem() on a path that represents a directory (or a path with no suffix), the entire final component is treated as the "stem." from pathlib import PurePath # Path representing a directory (or a file with no extension) dir_path ...
🌐
Python Module of the Week
pymotw.com › 3 › pathlib › index.html
pathlib — Filesystem Paths as Objects
import pathlib p = pathlib.PurePosixPath('./source/pathlib/pathlib_name.py') print('path : {}'.format(p)) print('name : {}'.format(p.name)) print('suffix: {}'.format(p.suffix)) print('stem : {}'.format(p.stem)) Although the suffix and stem values are similar to the values produced by os.path.splitext(), the values are based only on the value of name and not the full path. $ python3 pathlib_name.py path : source/pathlib/pathlib_name.py name : pathlib_name.py suffix: .py stem : pathlib_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 - As we have seen, Path objects only represent files but don't perform operations on them. However, they do have certain methods for common file operations. We will see how to use them in this section. Reading file contents is a fundamental operation in many Python applications. pathlib provides convenient shorthand methods for reading files as either text or raw bytes.
🌐
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 this example, we import the Pathlib module. Then, we create a new variable called p to store the path. Here, we use the Path object from Pathlib with a built-in variable in Python called file to refer to the file path we are currently writing in it example.py.
🌐
Steve's Data Tips and Tricks
spsanderson.com › steveondata › posts › 2025-07-23
Reading and Writing Files in Python: A Beginner’s Journey with pathlib – Steve's Data Tips and Tricks
from pathlib import Path # 1. Create directory practice_dir = Path('practice_files') practice_dir.mkdir(exist_ok=True) # 2. Create three files files_data = { 'file1.txt': 'This is the first file', 'file2.txt': 'This is the second file', 'file3.txt': 'This is the third file' } for filename, content in files_data.items(): file_path = practice_dir / filename file_path.write_text(content) ... file1.txt: This is the first file file2.txt: This is the second file file3.txt: This is the third file · Use pathlib for modern, cross-platform file handling ... Working with files in Python has become so much easier since I discovered pathlib.
🌐
GitHub
github.com › python › cpython › issues › 126537
add setter for pathlib.stem · Issue #126537 · python/cpython
November 7, 2024 - add setter for pathlib.stem#126537 · Copy link · Labels · type-featureA feature request or enhancementA feature request or enhancement · thawn · opened · on Nov 7, 2024 · Issue body actions · 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') 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) It would be much cleaner, if I could instead just do the following: if file_path.exists(): file_path.stem += '-1' This is a minor feature, which does not need previous discussion elsewhere ·
🌐
Python Morsels
pythonmorsels.com › pathlib-module
Python's pathlib module - Python Morsels
November 18, 2024 - So pathlib seems pretty great... but do you ever need to use a string to represent a file path? Nope. Pretty much never. Nearly every utility built-in to Python which accepts a file path will also accept a pathlib.Path object.