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'] W…
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
To access the individual “parts” (components) of a path, use the following property: ... >>> p = PurePath('/usr/bin/python3') >>> p.parts ('/', 'usr', 'bin', 'python3') >>> p = PureWindowsPath('c:/Program Files/PSF') >>> p.parts ('c:\\', 'Program Files', 'PSF') (note how the drive and local root are regrouped in a single part) The parent, name, stem, and suffix properties describe different parts of a path.
🌐
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.
🌐
Mopicmp
mopicmp.github.io › python-pathlib › path-stem.html
Path.stem - Python Pathlib | BetterDocs
for filepath in output_dir.glob("*.lua"): if filepath.name.endswith(".meta"): continue # Filename format: owner__name.lua stem = filepath.stem if "__" in stem: owner, name = stem.split("__", 1) cached.add(f"{owner}/{name}") return cached def fetch_configs( self, query: str = "filename:init.lua path:nvim", max_repos: int = 500, progress_callback=None, ) -> Iterator[ConfigFile]: """ Fetch Neovim configurations from GitHub.
Find elsewhere
🌐
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.
🌐
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)
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
4 days ago - Handle file and folder paths the modern way with Python pathlib, a built-in module whose semantics work the same on every OS.
🌐
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 ·
🌐
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): ...
Author: python
🌐
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)
🌐
Medium
medium.com › aiadventures › file-paths-file-systems-90474a2e5461
File paths & file systems. I recently had few problems with paths… | by Shyam Rathod | aiadventures | Medium
March 16, 2021 - The pathlib module was introduced in Python to deal with challenges like finding the parent directory of a given file, create a unique file name that does not already exist, or few cases may involve only reading or writing files.
🌐
Texas Instruments
education.ti.com › en › bulletinboard › 2022 › pathtostem
TI’s Path to STEM Projects Are Now Available in Python
February 18, 2022 - Project titles are “Build a Speaker,” “Make a Switch From a Banana,” “Make a Mood Light,” “How Clean is the Water?,” “That’s Cool!,” and the culminating project, “How to Keep a Lizard Warm.” TI has recently updated the original Path to STEM projects to now include Python!
🌐
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'