修改 # -*- coding: utf-8 -*- import os path='.\\' #对目录下的文件进行遍历 for file in os.listdir(path): #判断是否是文件 if os.path.isfile(os.path.join(path,file))==True: if 'part' in file and '.rar' in file: temp = file.split('.') new_name = temp[0] + temp[1] + '.' + temp[2] os.rename(os.path.join(path,file),os.path.join(path,new_name)) 还原 # -*- coding: utf-8 -*- import os path='.\\' #对目录下的文件进行遍历 for file in os.listdir(path): #判断是否是文件 if os.path.isfile(os.path.join(path,file))==True: if 'part' in file and '.rar' in file: temp = file.split('part') new_name = temp[0] + '.part' + temp[1] os.rename(os.path.join(path,file),os.path.join(path,new_name))