文件名称修改
import os
from re import split
import shutil
# 提取文件名称
ym = 'C:/Users/Administrator/Desktop/源文件'
path = 'C:/Users/Administrator/Desktop/20201225'
# 获取该目录下所有文件,存入列表中
fileList_ym = os.listdir(ym)
fileList_path = os.listdir(path)
# # 创建新文件
# for index in range(3):
# f4 = open('C:/Users/Administrator/Desktop/新建文件夹/' + str(index) + '.xlsx','w',encoding = 'utf-8')
# f4.close()
n = 0
for i in fileList_path:
# 设置旧文件名(就是路径+文件名)
# ENBID = i.split('[', 2)[1].split(']',2)[0]
oldname = path + os.sep + fileList_path[n] # os.sep添加系统分隔符
# # 设置新文件名
# file = fileList[n].split('-', 2)
newname = path + os.sep + fileList_ym[n]
os.rename(oldname, newname) # 用os模块中的rename方法对文件改名
print(oldname, '======>', newname)
n += 1