代码主要被用来按照图片名称拷贝标签文件
"""
Created on Mon Aug 31 21:23:07 2020
@author: 奥利给
@author: deyiwang@qq.com
"""
import datetime
import io, os
import shutil
def record_name(inshore):
inshore_name = []
for roots, dirs, files in os.walk(inshore):
for index in range(len(files)):
formatFile = files[index].split('.')[-1]
if formatFile == 'jpg':
inshore_name.append(files[index].split('.')[0])
print(f'the length of list:{len(inshore_name)}')
return inshore_name
def search_name_copy(inshore_list, annotation_path):
count = 0
file_list = []
for roots, dirs, files in os.walk(annotation_path):
for index in range(len(files)):
formatName = files[index].split('.')[0]
if formatName in inshore_list:
count += 1
file_list.append(os.path.join(annotation_path, files[index]))
print(count)
return file_list
if __name__ == '__main__':
inshore = 'F:\\xxxx\\xxxx'
annotation = 'F:\\xxxx\\xxxx'
out_annotation = 'F:\\xxxx\\xxxx'
if not os.path.exists(out_annotation):
os.mkdir(out_annotation)
carry_list = search_name_copy(record_name(inshore), annotation)
for files in carry_list:
oldFilePath = files
newFilePath = os.path.join(out_annotation,files.split('\\')[-1])
shutil.copyfile(oldFilePath, newFilePath)