批量重命名
1 import os 2 3 # 1表示添加标志,2表示删除标志 4 funFlag = 1 5 fileOldName = "./renameDir/" 6 7 # 获取指定路径的所有文件名字 8 dirList = os.listdir(fileOldName) 9 10 for name in dirList: 11 print(name) 12 13 if funFlag == 1: 14 newName = "[东哥出品]-" + name 15 elif funFlag == 2: 16 num = len("[东哥出品]-") 17 newName = name[num:] 18 print(newName) 19 20 os.rename(fileOldName + name, fileOldName + newName) 21