>>> import os >>> path=os.path.dirname("C:/folder1/folder2/filename.xml") >>> path 'C:/folder1/folder2' >>> os.path.basename(path) 'folder2'