#coding:utf-8
import os
def re_fileName(path):
fileList = os.listdir(path)
for file in fileList:
used_fileName, extension = os.path.splitext(file)
replacename = used_fileName.replace('_normal', '_low')
new_file = replacename + extension;
os.chdir(path)
os.rename(file, new_file)
print("文件%s重命名成功,新的文件名为:%s" % (path + file, path + new_file))
if __name__ == '__main__':
# path="C:/Users/Administrator/Desktop/old/" # 目标路径
# path = "C:\\Users\\Administrator\\Desktop\\old\\" # 目标路径
path='/home/xpy/xl/workstation/Datasets/Low_Light_DukeMTMC/mix_bounding_box_train/'
# path = os.getcwd() # 获取当前目录
re_fileName(path)
|