如题。
import os
import shutil
fil_path = '/data/jn01_set'
ann_path = '/data/jn01_set/VOCdevkit/VOCjn01/Annotations'
img_path = '/data/jn01_set/VOCdevkit/VOCjn01/imges'
def mkdirs(path):
if not os.path.exists(path):
os.makedirs(path)
mkdirs(ann_path)
mkdirs(img_path)
items = os.listdir(fil_path)
i, j = 0, 0
for item in items:
fil_name = os.path.join(fil_path,item)
ann_name = os.path.join(ann_path,item)
img_name = os.path.join(img_path,item)
if os.path.isfile(fil_name):
if os.path.splitext(fil_name)[1] == '.xml':
shutil.move(fil_name, ann_name)
i += 1
print(item + '移动成功 ' + str(i))
elif os.path.splitext(fil_name)[1] == '.jpg':
shutil.move(fil_name, img_name)
j += 1
print(item + '移动成功 ' + str(j))
else:
pass
print('总计:' + 'xml ' + str(i) + ' , jpg ' + str(j))