import os from pathlib import Path import multiprocessing from tqdm import tqdm def delete_file(file_path): """删除指定的文件""" try: os.remove(file_path) return file_path except Exception as e: return e def find_and_delete_files(directory, suffix): """查找并删除指定后缀的文件""" # 使用rglob找到所有指定后缀的文件 files = list(Path(directory).rglob(f"*{suffix}")) if not files: print(f"No files with suffix '{suffix}' found in {directory}") return # 创建tqdm进度条 with multiprocessing.Pool() as pool: for _ in tqdm(pool.imap_unordered(delete_file, files), total=len(files), desc="Deleting files"): pass if __name__ == "__main__": directory = "/home/rcell/genshin_data" # 替换为目标目录 suffix = "latent.pt" # 替换为目标后缀 find_and_delete_files(directory, suffix)