Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get file name including parent folder.
import pathlib
path = pathlib.Path('home/path/to/file.txt')
root = path.parent.parent
# PosixPath('home/path')
path.relative_to(root)
# PosixPath('to/file.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.