码迷,mamicode.com
首页 > 编程语言 > 详细

python正则表达式从绝对路径中取文件名出来不加后缀(txt)

时间:2019-03-17 15:51:30      阅读:594      评论:0      收藏:0      [点我收藏+]

标签:pre   har   dialog   send   正则表达式   txt   正则   应用   --   

 1 正则表达式[^\\/:*?"<>|\r\n]+$    ---->取文件名包括后缀
 2 e.g.  >>>D:\PyCharm 2018.2.4\pythonWork\venv\Scripts\python.txt
 3         ->python.txt
 4 
5 正则表达式(.+?)\.txt ---->取上次结果去掉后缀 6 e.g. >>>python.txt 7 ->python

8 部分代码应用截取>>> 9 def send(): 10 sendfile = tk.Tk() 11 sendfile.withdraw() 12 13 file_path = filedialog.askopenfilename() 14 print(file_path) 15 16 newName = re.findall(r[^\\/:*?"<>|\r\n]+$,file_path) 17 newName = re.findall(r(.+?)\.txt,newName[0]) 18 19 os.system(python markup.py < %s > d:/%s.html %(file_path,newName[0]))

 

python正则表达式从绝对路径中取文件名出来不加后缀(txt)

标签:pre   har   dialog   send   正则表达式   txt   正则   应用   --   

原文地址:https://www.cnblogs.com/ZhangYuniang/p/10547066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!