from pathlib import Path标签:xml,suffix,3droom,python,pathlib,relative,Path From: https://blog.51cto.com/haoyonghui/6019267
a = Path(r'E:\python_apps\bk-pipline\x52_merge_workspace\time_flush\client\3droom\A - 1.17.0.xml')
b = Path(r'E:\python_apps\bk-pipline\x52_merge_workspace\time_flush')
relative_path = (
a.relative_to(b)
.with_name("A")
.with_suffix(Path("/1.17.0.xml").suffix)
)
print(relative_path)
输出: client\3droom\A.xml