话不多说,直接上代码1234567891011121314151617import osimport redef scan_files(directory, prefix=None, postfix=None): count = 0 for files in os.walk(directory): for file in files[2]: if "微信截图_" in file: count += 1 newname = re.sub("微信截图_","",file) os.rename(directory+file,directory+newname) break print("改名完成,一共改名{}个文件".format(count))if __name__ == '__main__': dir = r"xxx/xxx" # 这里写你的路径,记得加上前面的r,否则容易出错 scan_files(dir) 写在最后欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。