python获取文件名
2021-02-01 19:17
标签:col with RoCE ble pen lang pytho author odi 使用python+正则表达式获取一个路径的文件名 运行结果: python获取文件名 标签:col with RoCE ble pen lang pytho author odi 原文地址:https://www.cnblogs.com/wxhou/p/12812972.html#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import sys
sys.path.append(‘.‘)
__author__ = ‘1084502012@qq.com‘
import re
mp4_path = "D:\电影电视\我不是药神-2018_BD国语中字.mp4"
def get_file_name(path_string):
"""获取文件名称"""
pattern = re.compile(r‘([^/\\\|:""\*\?]+)\.\w+$‘)
data = pattern.findall(path_string)
if data:
return data[0]
if __name__ == ‘__main__‘:
print(get_file_name(mp4_path))
我不是药神-2018_BD国语中字
Process finished with exit code 0
喜欢python自动化测试或正在学习自动化测试的同学
欢迎加入我的QQ群:299524235(python自动化测试学习)
上一篇:Spring Boot
下一篇:springmvc注解——拙见