小武与python的相遇1 - strip-replace的使用

文件名字统一修改:

file_path = ‘Pinch’
roots = []

for root,dirs,files in os.walk(file_path):
roots.append(root)

for rt in roots:
for file in files:
old_path =os.path.join(rt,file)
if os.path.exists(old_path):
new_path =os.path.join(rt,rt.replace(’/’, ‘’)+file)
os.rename(old_path,new_path)
else:
pass

复制文件到文件夹:

file_path = ‘new_train’
jpg_path = glob.glob(file_path+’/////.jpg’)
xml_path = glob.glob(file_path+’/
////.xml’)
not_exits = []
JPEG_path = ‘/Users/shawnwu/Desktop/dataset/YOLOV3dataset/yolonew/VOCdevkit/VOC2007/JPEGImages’
XMl_path = ‘/Users/shawnwu/Desktop/dataset/YOLOV3dataset/yolonew/VOCdevkit/VOC2007/Annotations’
for jpg in jpg_path:
shutil.copy(jpg,JPEG_path)
for xml in xml_path:
shutil.copy(xml,XMl_path)

猜你喜欢

转载自blog.csdn.net/weixin_37721058/article/details/94650634
今日推荐