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: if file.find('_') isnot -1: os.remove(os.path.join(path, file)) print(file, "ok") a = a+1