可以更改文件名,文件夹等等,不管有没有后缀都可以更改哦,但是要注意后缀名是否修改,是否需要
import datetime
import os
Yesterday = ((datetime.datetime.now()) + datetime.timedelta(days=0)).strftime("%Y%m%d") # 采集数据时的日期
def fun1():
path = r'C:\Users\Administrator\Desktop\报表/' #路径-文件夹必须要有!!!!
path1 = r'C:\Users\Administrator\Desktop\报表\报表/' #路径-文件夹必须要有!!!
files = os.listdir(path)
list = []
for file in files:
#多文件的话尽量保持文件名唯一性
#比如:绿豆饼和绿豆这是俩个东西 搞清楚先后关系----旧文件名===绿豆饼 然后再运行 旧文件名==绿豆的
#又例如:绿豆饼1和绿豆饼2 ----旧文件名===绿豆饼
if '旧文件名' in file or '类似旧文件名' in file:
list.append(file)
else:
continue
print(list)
i = 0
for x in list:
old = x
new = '新文件名' + str(i) + '--' + str(Yesterday) + '.xls'
os.rename(path + old, path1 + new)
i = i + 1