xxxxxxxxxx
from pathlib import Path
Path("/tmp/d/a.dat").name
xxxxxxxxxx
import os
filename = os.path.basename(path)
name, ext = os.path.splitext(filename)
xxxxxxxxxx
from pathlib import Path
>>> p = r"C:\Users\shali\OneDrive\code\setTheory.pdf"
>>> Path(p).anchor
'C:\\'
>>> Path(p).parent
WindowsPath('C:/Users/shali/OneDrive/code')
>>> Path(p).name
'setTheory.pdf'
>>> Path(p).stem
'setTheory'
>>> Path(p).suffixes
['.pdf']