Python快速批量修改特定文件夹的文件名
import os
import re
import sys
def renameall():
fileList = os.listdir(r"G:\Dog\Tibetan Mastiff")
print("修改前:" + str(fileList))
currentpath = os.getcwd()
os.chdir(r"G:\Dog\Tibetan Mastiff")
num = 1
for fileName in fileList:
pat = ".+\.(jpg|png|gif)"
pattern = re.findall(pat, fileName)
os.rename(fileName, ('Tibetan Mastiff'+str(num) + '.' + pattern[0]))
num = num + 1
print("---------------------------------------------------")
os.chdir(currentpath)
sys.stdin.flush()
print("修改后:" + str(os.listdir(r"G:\Dog\Tibetan Mastiff")))
renameall()
|