Download code/delete_files_fast.py from rcell233/magvits_data: direct link, hf CLI and curl.
- Browser
- Download file 942 Bytes
-
https://huggingface.co/datasets/rcell233/magvits_data/resolve/main/code/delete_files_fast.py
- Command line
-
hf download hf://datasets/rcell233/magvits_data/code/delete_files_fast.py
-
curl -L -o delete_files_fast.py https://huggingface.co/datasets/rcell233/magvits_data/resolve/main/code/delete_files_fast.py
942 Bytes
| 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) | |