小武与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)

上一篇:第四周Android练习


下一篇:Metasploit攻击win7实例