import os base=os.path.basename('/root/dir/sub/file.ext') print(base) #'file.ext' print(os.path.splitext(base)) #('file', '.ext') print(os.path.splitext(base)[0]) #'file'