python 根据txt文件,批量复制图片

# -*- coding: utf-8 -*-
import shutil

def objFileName():
    local_file_name_list = "/home/li/data/data(RGB)/train/aug_data_scale_0.9/aug_gt_scale_0.9_3.txt"
    obj_name_list = []
    for i in open(local_file_name_list, 'r'):
        obj_name_list.append(i.replace('\n', ''))
    return obj_name_list

def copy_img():
    local_img_name = r'/home/li/data/data(RGB)/train/aug_data_scale_0.9'
    # 指定要复制的图片路径
    path = r'/home/li/data/data(RGB)/train/aug_data_scale_0.9/33'
    # 指定存放图片的目录
    for i in objFileName():
        new_obj_name = i
        shutil.copy(local_img_name + '/' + new_obj_name, path + '/' + new_obj_name)

if __name__ == '__main__':
    copy_img()

 

你可能感兴趣的:(code)