import os
path = 'G:\\radar_tf_img'
for i in os.listdir(path):
# print(i)
path_file = os.path.join(path, i)
if os.path.isfile(path_file):
os.remove(path_file)
else:
for f in os.listdir(path_file):
path_file2 = os.path.join(path_file, f)
if os.path.isfile(path_file2):
os.remove(path_file2)
else:
for k in os.listdir(path_file2):
path_file3 = os.path.join(path_file2,k)
if os.path.isfile(path_file3):
os.remove(path_file3)
else:
for m in os.listdir(path_file3):
path_file4 = os.path.join(path_file3,m)
os.remove(path_file4)
print('ok')
这个可以清空3级文件夹