2020年1月5日星期日

Python: batch copy missing files with same name

Function: Batch copy missing files with the same name from other folders

# _*_ 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/'

################################transfer training set #####################################
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)


没有评论:

发表评论