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
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
5 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().
Discussions

Why You Should Start Using Pathlib As An Alternative To the OS Module
Is this not already a popular opinion? More on reddit.com
🌐 r/Python
142
614
December 16, 2021
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
🌐
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().
🌐
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.
🌐
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.
🌐
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 - The pathlib module, introduced in Python 3.4, provides an object-oriented approach to file system paths.
🌐
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 Tutorial
pythontutorial.net › home › python standard library › python path
Python Path: Interact with File System Using Path from pathlib
March 27, 2025 - In this tutorial, you'll learn how to use the Python Path class from the pathlib to interact with the file system easily and effectively.
🌐
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.
🌐
DataCamp
datacamp.com › home › tutorials › python › a comprehensive guide to 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 ...
🌐
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)
🌐
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
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths — Python 3.15.2 documentation
>>> 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.
🌐
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.
🌐
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
🌐
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 ·
🌐
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.
🌐
Programiz
programiz.com › python-programming › examples › file-name-from-file-path
Python Program to Get the File Name From the File Path | Programiz
March 14, 2024 - Python Strings · import os # file name with extension file_name = os.path.basename('/root/file.ext') # file name without extension print(os.path.splitext(file_name)[0]) Output · file · basename() gives the name of the last file/folder of the path, whereas splitext() splits the file name into filename and extension. import os print(os.path.splitext(file_name)) Output · ('file', '.ext') from pathlib import Path print(Path('/root/file.ext').stem) Output ·