1. 程式人生 > 其它 >刪除某個資料夾下所有指定檔案

刪除某個資料夾下所有指定檔案

import os

path = "./experiment_normal"  ## modify the path according to your own need

del_file=['training_args.bin','config.json', 'pytorch_model.bin', 'special_tokens_map.json', 'tokenizer_config.json', 'vocab.txt'] ## modify it

for dir_path,dir_name,file_name in os.walk(path):
    for file
in file_name: if file in del_file: os.remove(os.path.join(dir_path,file))

伺服器被憨憨搞炸了,一晚上結果白跑,把模型檔案都刪掉唄