Created
July 10, 2020 06:29
-
-
Save Keiku/cbd43a53b2ff32ea4bb6e028a8925e11 to your computer and use it in GitHub Desktop.
Get file name including parent folder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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