get last dir of path python code example
Example 1: get dirname to last directory node
path.basename(path.dirname(filename))
Example 2: get last element path
>>> os.path.basename(os.path.normpath('/folderA/folderB/folderC/folderD/'))
'folderD'
path.basename(path.dirname(filename))
>>> os.path.basename(os.path.normpath('/folderA/folderB/folderC/folderD/'))
'folderD'