title: Clean way to get the "true" stem of a Path object?
body: <p>Expected inputs and outputs:</p>
  
  <pre><code>a                 -&gt; a
  a.txt             -&gt; a
  archive.tar.gz    -&gt; archive
  directory/file    -&gt; file
  d.x.y.z/f.a.b.c   -&gt; f
  logs/date.log.txt -&gt; date # Mine!
  </code></pre>
  
  <p>Here's my implementation that feels dirty to me:</p>
  
  <pre><code>&gt;&gt;&gt; from pathlib import Path
  &gt;&gt;&gt; example_path = Path("August 08 2015, 01'37'30.log.txt")
  &gt;&gt;&gt; example_path.stem
  "August 08 2015, 01'37'30.log"
  &gt;&gt;&gt; example_path.suffixes
  ['.log', '.txt']
  &gt;&gt;&gt; suffixes_length = sum(map(len, example_path.suffixes))
  &gt;&gt;&gt; true_stem = example_path.name[:-suffixes_length]
  &gt;&gt;&gt; true_stem
  "August 08 2015, 01'37'30"
  </code></pre>
  
  <p>Because it breaks on <a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" rel="noreferrer"><code>Path</code></a>s without suffixes:</p>
  
  <pre><code>&gt;&gt;&gt; ns_path = Path("no_suffix")
  &gt;&gt;&gt; sl = sum(map(len, ns_path.suffixes))
  &gt;&gt;&gt; ns_path.name[:-sl]
  ''
  </code></pre>
  
  <p>So I need to check if the <code>Path</code> has a suffix first:</p>
  
  <pre><code>&gt;&gt;&gt; def get_true_stem(path: Path):
  ...     if path.suffix:
  ...         sl = sum(map(len, path.suffixes))
  ...         return path.name[:-sl]
  ...     else:
  ...         return path.stem
  ...
  &gt;&gt;&gt;
  &gt;&gt;&gt; get_true_stem(example_path)
  "August 08, 2015, 01'37'30"
  &gt;&gt;&gt; get_true_stem(ns_path)
  "no_suffix"
  </code></pre>
  
  <p>And this is my current use case:</p>
  
  <pre><code>&gt;&gt;&gt; file_date = datetime.strptime(true_stem, "%B %d %Y, %H'%M'%S")
  &gt;&gt;&gt; file_date
  datetime.datetime(2015, 8, 8, 1, 37, 30)
  &gt;&gt;&gt; new_dest = format(file_date, "%Y-%m-%dT%H:%M:%S%z") + ".log" # ISO-8601
  &gt;&gt;&gt; shutil.move(str(example_path), new_dest)
  </code></pre>
  
  <p>Thanks.</p>