import os
path
= '/media/li_hiayu/D/Caltech/JPEG'
outpath
= '/media/li_hiayu/D/Caltech/JPEGImages'
if not os
.path
.exists
(outpath
):
os
.makedirs
(outpath
)
for img
in os
.listdir
(path
):
if img
!= '.DS_Store':
name
= os
.path
.splitext
(img
)
img_segment
= name
[0]
name_segment
= img_segment
.split
("_")
first_segment
= name_segment
[0]
second_segment
= name_segment
[1]
three_segment
= name_segment
[2]
four_segment
= name
[1]
str = "set00"
org_name
= os
.path
.join
(path
,img
)
changed_name
= outpath
+"//"+str+"_"+second_segment
+"_"+three_segment
+four_segment
os
.rename
(org_name
,changed_name
)
提醒:修改之后,原来文件夹中的图片就完全转移到outpath中,也就是JPEG就清空了 The end.
转载请注明原文地址:https://tech.qufami.com/read-14348.html