Python Program to Get the File Name From the File Path (Using Path module)

bookmark

from pathlib import Path

print(Path('/root/file.ext').stem)

 

Output

file