目的:将一个文件夹下的部分文件(在txt文件夹里)移动到另一文件夹
txt文件夹如下:
代码:
import os
import shutil
txt_path = '/home/zhaotongdong/桌面/unnormal.txt'
img_path = '/home/zhaotongdong/goole_download/mmdetection/normal_predic_false_1/'
new_path = '/home/zhaotongdong/goole_download/mmdetection/normal_true'
img_path_list = os.listdir(img_path)
with open(txt_path) as f:
img_id = f.readlines()
img_list = []
for i in img_id:
img_name = 'train' + '_' + i.strip() + '.json'
img_list.append(img_name)
for i in img_path_list:
if i not in img_list:
json_path = img_path + i
shutil.copy(json_path, new_path)