1 import os 2 path = "E:\\test\\" 3 drop_str= ‘_00001‘ 4 #获取该目录下所有文件,存入列表中 5 fileList=os.listdir(path) 6 for file in fileList: 7 old=path + file 8 new=path + ‘‘.join(file.split(drop_str)) #join和split方法 9 os.rename(old, new) #rename方法 10 print(old, ‘======>‘, new)
原文:https://www.cnblogs.com/wstudyblog/p/15011265.html