Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 11, 2020 10:06
Show Gist options
  • Save openroomxyz/4eee22604e8d3831323c2ebc78621200 to your computer and use it in GitHub Desktop.
Save openroomxyz/4eee22604e8d3831323c2ebc78621200 to your computer and use it in GitHub Desktop.
Python : How to get parts of file path ( folder path, filename with extension, without , only extension ) ?
import os
def getPartsOfPath(path):
path_to_folder = os.path.dirname(path)
file_name_with_extension = os.path.basename(path)
file_name_without_extension, extension = os.path.splitext(file_name_with_extension)
return (path_to_folder, file_name_with_extension, file_name_without_extension, extension)
getPartsOfPath("C:\\Users\\C\\Desktop\\Cosmos\\test.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment