import os, re
for item in os.listdir('.'):try:#因为py文件在同目录下,当search函数匹配rename.py时.group会出错
newname = re.sub("摩登家庭.H265.1080P.SE04"+"\.\d+\.","Modern.Family.S04.E"+ re.search("(?<=\.)\d+\.", item).group()+"1080p.H265.", item)
os.rename(item, newname)except:pass