import os suffix_name_list = [".pdb", ".ilk"] def find_file(path): # 遍历文件夹 for i in os.listdir(path): # 获取文件后缀名 suffix_name = os.path.splitext(i)[-1] if suffix_name in suffix_name_list: # 删除文件 os.remove(path + "\" + i) print(path + "\" + i + "已删除...") # 如果是文件夹就递归遍历 if os.path.isdir(path + "\" + i): find_file(path + "\" + i) if __name__ == '__main__': find_file("F:ProjectsC++Project")