Skip to content

Instantly share code, notes, and snippets.

@simryang
Last active December 10, 2022 16:13
Show Gist options
  • Save simryang/f9f2f94319fa9f2e43122a7d78613aa5 to your computer and use it in GitHub Desktop.
Save simryang/f9f2f94319fa9f2e43122a7d78613aa5 to your computer and use it in GitHub Desktop.
split ext filename from full path
import os
from pathlib import Path
p = "/home/pi/src/projA/kk.c"
pp = os.path.splitext(p)
# pp = ('/home/pi/src/projA/kk', 'c')
print(f"filename with path={pp[0]}, extension={pp[1]}")
p1 = Path(p)
p1ext = p1.suffix
p1name = p1.name
print(f"filename={p1}, ext={p1ext}, name={p1name}")
# filename=/home/pi/src/projA/kk.c, ext=.c, name=kk.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment