# coding=utf8
import os, re
# 参考地址
class Ren:
def __init__(self, file_dir, old_name, new_name):
self.file_dir = file_dir
self.old_name = old_name
self.new_name = new_name
def file_name(self):
L = []
if os.path.exists(self.file_dir):
for root, dirs, files in os.walk(self.file_dir):
for file in files:
if os.path.splitext(file)[0] == self.old_name:
L.append(os.path.join(root, file))
else:
print('文件夹不存在!!')
return L
def ren_name(self):
for file in self.file_name():
try:
str = file.replace(self.old_name, self.new_name)
os.rename(file, str)
print('%s 修改成功!!!' % file)
except(FileExistsError):
print('%s文件已存在' % str)
continue
FILE_DIR = r'./全部服务_slices'
ren = Ren(FILE_DIR, "ic_all_service_cysf", "ic_all_service_jkda")
ren.ren_name()
08-20
08-20