Answers for "pathlib get file names from a path"

33

python get filename from path

import os
print(os.path.basename(your_path))
Posted by: Guest on February-28-2020
0

pathlib path get filename with extension

>>> from pathlib import Path
>>> p = Path("/home/user/Downloads/repo/test.txt")
>>> print(p.stem)
test
>>> print(p.name)
test.txt
Posted by: Guest on May-20-2021

Code answers related to "pathlib get file names from a path"

Python Answers by Framework

Browse Popular Code Answers by Language