#coding:utf-8
# 任务需要,需要删除多余的文件,手动删除太麻烦,几行python搞定
import os
from glob import glob
path = r"/media/icml-014/peixu/MyData/2019brain/valid/*" # 获取到目录
all_file = glob(path) # 得到该目录下的所有文件
for i in range(len(all_file)):
filename = all_file[i]
print("filename:",filename) #获取子目录文件名
sub_file = os.path.join(path, filename)
print("sub_file:", sub_file)
all_sub_file = glob(os.path.join(sub_file,"*")) # 得到子目录下所有文件
for j in range(len(all_sub_file)):
sub_file_name = all_sub_file[j]
print("sub_file_name:", sub_file_name)
name = sub_file_name.split("f32.")[-1]
if name =="pkl": # 找到自己要删出的文件类型,我删除的文件类型是.pkl文件。
print("del_sub_file_name:", sub_file_name)
os.remove(sub_file_name) # 进行删除