仅作为记录,大佬请跳过。
直接上代码
# 删除文件夹图片
import os
import glob
import shutil
path = "/Data4T/dataset_her2/dataset_her2_server_five-class_new_v2/train/0"
paths = glob.glob(os.path.join(path, '*.png'))
# 输出所有文件和文件夹
# for file in paths:
for i in range(len(paths)):
if i < len(paths)-70000:
shutil.move(paths[i],'/Data4T/dataset_her2/dataset_her2_server_five-class_new_v2_train-non-use/0')
# print(paths[i])
注
只需修改70000
参数(保留的文件数)
(原文件夹想保留3个文件,就写3)
另