python读取文件名后重命名原文件

来源:互联网 发布:淘宝默认头像 黄人 编辑:程序博客网 时间:2024/05/18 02:46
import os.path
from datetime import datetime
import re
path='/home/siyanlou/output_1981.10.21.txt'
haha=os.path.basename(path)
format="output_%Y.%m.%d.txt"
t=datetime.strptime(haha,format)
s=t.weekday()+1
S=str(s)
os.rename("/home/shiyanlou/output_1981.10.21.txt","/home/shiyanlou/output_1981-10-21-"+S+".txt")
0 0
原创粉丝点击