File size: 942 Bytes
24303c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)