path = "C:\\Users\\Administrator\\Desktop\\testB"# 文件路径 a = 1 for file in os.listdir(path): b = os.path.join(path, file) if os.path.isfile(os.path.join(path, file))==True: regex = re.compile(r'\d+') num = int(max(regex.findall(file))) if num > 5000: os.remove(os.path.join(path, file)) print(file, "ok") a = a+1