import os path="./" fileType=input("文件类型:") delSubStr=input("删除串:") replaceStr=input("替换串:") for file in os.listdir(path): suffix=os.path.splitext(file)[1] if suffix==fileType: newFileName=os.path.splitext(file)[0].replace(delSubStr,replaceStr,1)+fileType os.rename(file,newFileName)