import os # 导入 os 模块,用于与操作系统进行交互,例如执行系统命令
strPathAndFile=r"C:\Tools\abc.txt"
strPath, strFile = os.path.split(strPathAndFile)
print(strPath) # C:\Tools
print(strFile) # abc.txt
input("Press Enter to exit...")
运行结果:
C:\Tools
abc.txt
Press Enter to exit...