功能:从别的文件夹批量拷贝缺失同名文件
参考链接:https://www.computationalimaging.cn/2020/01/python-batch-copy-missing-files-with.html
# _*_ encoding:utf-8 _*_
import os
import sys
from shutil import copyfile
origin_A_train_path = './animeFaces/A/train/'
origin_A_test_path = './animeFaces/A/test/'
################################转移训练集#####################################
mode = 'train'
target_B_train_path = './data_superpixel_specifiedColor/B/'+mode+'/'
C_train_path = './data_superpixel_specifiedColor/C/'+mode+'/'
B_trainfile_name = os.listdir(target_B_train_path)
for image_index in range(len(B_trainfile_name)):
image_name = B_trainfile_name[image_index]
origin_image_file = origin_A_train_path + image_name
if not os.path.exists(origin_image_file):
print('test')
origin_image_file = origin_A_test_path + image_name
C_image_file = C_train_path + image_name
copyfile(origin_image_file,C_image_file)
################################转移测试集#####################################
# mode = 'test'
# target_B_train_path = './data_superpixel_specifiedColor/B/'+mode+'/'
# C_train_path = './data_superpixel_specifiedColor/C/'+mode+'/'
# B_trainfile_name = os.listdir(target_B_train_path)
# for image_index in range(len(B_trainfile_name)):
# image_name = B_trainfile_name[image_index]
# origin_image_file = origin_A_train_path + image_name
# if not os.path.exists(origin_image_file):
# print('test')
# origin_image_file = origin_A_test_path + image_name
# C_image_file = C_train_path + image_name
# copyfile(origin_image_file,C_image_file)