Created
April 11, 2020 10:06
-
-
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 ) ?
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 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