python获取路径中的文件名

获取路径中的文件名
一、字符串分割–split()函数
path=“K:\Project\FilterDriver\DriverCodes\hello.txt”
print(path.split(’\’)[-1])
二。使用basename()函数
import os.path
filePath=“K:/Project/FilterDriver/DriverCodes/hello.txt”
print(os.path.basename(filePath))
执行的结果仍然是hello.txt。

发布了32 篇原创文章 · 获赞 24 · 访问量 6129

猜你喜欢

转载自blog.csdn.net/weixin_44517681/article/details/102820832