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
February 23, 2026 - >>> 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.
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
January 11, 2025 - You’re using .with_stem() to create the new filename without changing the extension. The actual copying takes place in the highlighted line, where you use .read_bytes() to read the content of source and then write this content to destination using .write_bytes(). While it’s tempting to use pathlib for everything path related, you may also consider using shutil for copying files.
🌐
Mopicmp
mopicmp.github.io › python-pathlib › path-stem.html
Path.stem - Python Pathlib | BetterDocs
Practical code examples showing how Path.stem is used in real projects.
🌐
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).
🌐
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.
🌐
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…
🌐
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().
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 - from pathlib import Path path = Path('readme.txt') print(path.name)Code language: Python (python) Output: readme.txtCode language: Python (python) To get the file name without extension, you use the stem property: from pathlib import Path path = Path('readme.txt') print(path.stem)Code language: ...
🌐
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" {
🌐
Miguendes
miguendes.me › python-pathlib
Python pathlib Cookbook: 57+ Examples to Master It (2022)
July 5, 2024 - A mega tutorial to learn by example the idiomatic way to work with paths in Python 3 using the pathlib module.
🌐
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 ...
🌐
ZetCode
zetcode.com › python › pathlib
Python pathlib - working with files and directories in Python with pathlib
$ 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
import os from pathlib import Path multi_dot_file = 'archive.tar.gz' # pathlib method p = Path(multi_dot_file) print(f"pathlib stem: {p.stem}") # archive.tar # os.path method name_part, ext_part = os.path.splitext(multi_dot_file) print(f"os.path name part: {name_part}") # archive.tar print(f"os.path extension part: {ext_part}") # .gz · Observation In this specific case (archive.tar.gz), both methods behave similarly by only stripping the last extension. The main benefit of pathlib is its object-oriented structure and platform-independent logic. For modern Python code, the best practice is to use pathlib exclusively for path manipulation, which avoids these interoperability issues and makes your code cleaner and more robust across different operating systems.
🌐
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)
Author   thawn
🌐
W3Schools Blog
w3schools.blog › home › python path
Python Path - w3schools.blog
September 4, 2018 - It is the first step when starting a python work. ... Open the Control Panel. Click on System and Security. Click on System. Click on Advanced System settings on the left corner. Click on Environment Variable tab. Click on new tab of user variables.
🌐
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