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.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 ...
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
February 23, 2026 - This is commonly called the file extension. Changed in version 3.14: A single dot (”.”) is considered a valid suffix. ... >>> PurePosixPath('my/library.tar.gar').suffixes ['.tar', '.gar'] >>> PurePosixPath('my/library.tar.gz').suffixes ['.tar', '.gz'] >>> PurePosixPath('my/library').suffixes [] Changed in version 3.14: A single dot (”.”) is considered a valid suffix. ... >>> PurePosixPath('my/library.tar.gz').stem 'library.tar' >>> PurePosixPath('my/library.tar').stem 'library' >>> PurePosixPath('my/library').stem 'library'
Discussions

python - Clean way to get the "true" stem of a Path object? - Stack Overflow
As pointed out in the comments ... have an extension with more than 2 suffixes. Although this doesn't sound very likely (and pathlib itself doesn't have a native way to deal with it), if you wanted to use pathlib uniquely, you could use: >>> Path('logs/date.log.txt.foo').with_suffix('').with_suffix('').stem ... More on stackoverflow.com
🌐 stackoverflow.com
string - How do I get the filename without the extension from a path in Python? - Stack Overflow
How do I get the filename without the extension from a path in Python? "/path/to/some/file.txt" → "file" More on stackoverflow.com
🌐 stackoverflow.com
python - Adding another suffix to a path that already has a suffix with pathlib - Stack Overflow
I was converting some old Python code to use pathlib instead of os.path for most path-related operations, but I ended up with the following problem: I needed to add another extension to a path that More on stackoverflow.com
🌐 stackoverflow.com
pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot
BPO 38624 Nosy @pitrou Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state. Show more details GitHub fields: assignee = None closed... More on github.com
🌐 github.com
7
October 28, 2019
🌐
GitHub
github.com › python › cpython › issues › 114610
`pathlib.PurePath.with_stem('')` promotes file extension to stem · Issue #114610 · python/cpython
January 26, 2024 - Bug report >>> pathlib.PurePath('foo.jpg').with_stem('').stem '.jpg' The with_stem() call should raise ValueError, as it's impossible for a filename to have an empty stem and a non-empty suffix. Linked PRs gh-114612 gh-114613
Author   barneygale
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
January 11, 2025 - ... When you want to rename files, you can use .with_stem(), .with_suffix(), or .with_name(). They return the original path but with the filename, the file extension, or both replaced.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-pathlib-module-in-python
Python Path – How to Use the Pathlib Module with Examples
May 10, 2022 - This is similar to the .with_name() method. The .with_stem() changes the name of the last component temporarily. Also, if the given path doesn't contain a name, an error will occur.
Find elsewhere
🌐
Runebook.dev
runebook.dev › en › docs › python › library › pathlib › pathlib.PurePath.stem
python - Beyond the Extension: A Guide to pathlib.stem
from pathlib import Path def process_file_path(p: Path): """Processes a path using only pathlib properties.""" base_name = p.stem full_extension = "".join(p.suffixes) # Combines all suffixes (e.g., .tar.gz) print(f"Base: {base_name}") print(f"Extension: {full_extension}") process_file_path(Path('data/archive.tar.gz')) # Output: # Base: archive.tar # Extension: .tar.gz ... The traceback module in Python provides tools to extract, format, and print stack traces.
🌐
TradingCode
tradingcode.net › python › filename-without-last-extension
Get filename with extension removed: here's how in Python
Then we get the path’s filename with no last extension. For that we call the stem property on the path object in the file_path variable. We assign the returned filename to the file_no_ext variable.
🌐
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" {
🌐
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") ...
🌐
Inspired Python
inspiredpython.com › article › common-path-patterns
Common Path Patterns • Inspired Python
>>> Path('.bashrc').stem '.bashrc' If you just want the filename portion of the path, but with the extension, use name: >>> Path('/opt/hello.txt').name 'hello.txt' You can split a path into all its component parts with the parts property · >>> Path('/var/log/dmesg').parts ('/', 'var', 'log', 'dmesg') This is particularly useful if you want to check that parts of a Path exist within a certain hierarchy of directories.
🌐
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).
🌐
IONOS
ionos.com › digital guide › websites › web development › python pathlib
How does Python pathlib work and what are its benefits?
June 18, 2025 - This creates a new file name without changing the file extension. This is an example of the ap­pro­pri­ate code: from pathlib import Path source = Path("ExampleList.md") destination = source.with_stem("new_example") destination.write_bytes(source.read_bytes())python
🌐
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 DZ | Medium
July 19, 2023 - To rename a file, we need to create a new path with the new name. We can use the with_stem method to replace the name of the file (without the extension) and then rename the file
🌐
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 - activity = <Date 2019-10-29.01:59:29.319> actor = 'xtreak' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = <Date 2019-10-28.22:54:26.232> creator = 'inyeollee' dependencies = [] files = [] hgrepos = [] issue_num = 38624 keywords = [] message_count = 1.0 messages = ['355600'] nosy_count = 2.0 nosy_names = ['pitrou', 'inyeollee'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue38624' versions = ['Python 3.8'] GH-82805: Fix handling of single-dot file extensions in pathlib #118952
Author   inyeollee
🌐
Mathspp
mathspp.com › blog › module-pathlib-overview
mathspp – take your Python 🐍 to the next level 🚀
with_stem: change the stem of a path (the name, minus the extension) (Python 3.9+); and · with_suffix: change the suffix (extension) of a path. To copy or move a file/directory, you can use the methods · copy & copy_into · move & move_into ...
🌐
Python.org
discuss.python.org › python help
Correct way to remove all file extensions from a path with pathlib? - Python Help - Discussions on Python.org
January 18, 2021 - If my file has multiple extensions, such as library.tar.gz, then .stem only removes the last one. How do I remove all of them? Is this how I’m expected to do it: from pathlib import Path filename = Path('file.tar.gz') …
🌐
PyPI
pypi.org › project › extended-pathlib
extended-pathlib · PyPI
This differs from Path.stem, which returns the final path component stripped of its extension. This returns the full path stripped of its extension. ... Writes a binary file. This is the standard pathlib write_bytes() that was introduced in ...
      » pip install extended-pathlib
    
Published   Jan 28, 2021
Version   0.5.0