Skip to content

Instantly share code, notes, and snippets.

@travis23
Created January 11, 2019 14:26
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 travis23/80ded409196b5e5fc1bf28c9a7153139 to your computer and use it in GitHub Desktop.
Save travis23/80ded409196b5e5fc1bf28c9a7153139 to your computer and use it in GitHub Desktop.
[get filename from path] #python #filename #ntpath #path
# See
# https://stackoverflow.com/questions/8384737/extract-file-name-from-path-no-matter-what-the-os-path-format
import ntpath
path_to_file = r"C:\a\b\s\d\f_a\aasdas_o_g.json"
print(ntpath.basename(path_to_file)
# Output:
# aasdas_o_g.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment