Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created July 10, 2020 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keiku/cbd43a53b2ff32ea4bb6e028a8925e11 to your computer and use it in GitHub Desktop.
Save Keiku/cbd43a53b2ff32ea4bb6e028a8925e11 to your computer and use it in GitHub Desktop.
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