Python文件批量改名

import os

rootimgs = 'D:\dataset\cityscapes\cityscape_voc_foggy\JPEGImages\\'
rootxmls = 'D:\dataset\cityscapes\cityscape_voc_foggy\Annotations\\'
allusedxmls = []
file_imgs = os.listdir(rootimgs)
file_xmls = os.listdir(rootxmls)
for file_xml in file_xmls:
    file_name = file_xml[:-4] + '_foggy_beta_0.005.xml'
    oldname = rootxmls + file_xml
    newname = rootxmls + file_name
    os.rename(oldname, newname)

承接Matlab、Python和C++的编程,机器学习、计算机视觉的理论实现及辅导,本科和硕士的均可,咸鱼交易,专业回答请走知乎,详谈请联系QQ号757160542,非诚勿扰。

本文同步分享在 博客“于小勇”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

评论

暂无评论