os.path.basename(os.path.normpath('/folderA/folderB/folderC/folderD/')) >>> folderD use this to get last value