Skip to content

Instantly share code, notes, and snippets.

@jmquintana79
Last active October 15, 2024 14:42
Show Gist options
  • Save jmquintana79/374660a6ebef2f8d78d9b81dff833d29 to your computer and use it in GitHub Desktop.
Save jmquintana79/374660a6ebef2f8d78d9b81dff833d29 to your computer and use it in GitHub Desktop.
import os
# given a path file
path = '/ruta/a/tu/carpeta/fichero.txt'
# parse filename
file_name = os.path.basename(path)
print(file_name) # Output: 'fichero.txt'
# pase folder name
folder_name = os.path.dirname(path)
print(folder_name) # Output: '/ruta/a/tu/carpeta'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment