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 get each and every suffix, currently, there is no way to extract first part ('CurveFile') without doing string manipulation.
๐ŸŒ
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.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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") ...
๐ŸŒ
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
๐ŸŒ
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" {
๐ŸŒ
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.
๐ŸŒ
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') โ€ฆ
๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ get-file-extension-python
3 Best Ways to Get a File Extension in Python (With Examples)
The os module provides the os.path.splitext() function, which splits a file path into the base name and its extension. This method is tried and tested, making it an ideal choice for many traditional Python projects.