python-批量重命名文件
import osclass ImageRename():def __init__(self):self.path = '/home/lab305/Work/d3aapi/tools/data/VOCdevkit/VOC2007/Annotations/'def rename(self):filelist = os.listdir(self.path)to...
·
import os
class ImageRename():
def __init__(self):
self.path = '/home/lab305/Work/d3aapi/tools/data/VOCdevkit/VOC2007/Annotations/'
def rename(self):
filelist = os.listdir(self.path)
total_num = len(filelist)
i = 0
for item in filelist:
if item.endswith('.xml'):
src = os.path.join(os.path.abspath(self.path), item)
dst = os.path.join(os.path.abspath(self.path), '0000' + format(str(i), '0>3s') + '.xml')
os.rename(src, dst)
print 'converting %s to %s ...' % (src, dst)
i = i + 1
print 'total %d to rename & converted %d jpgs' % (total_num, i)
if __name__ == '__main__':
newname = ImageRename()
newname.rename()
更多推荐
已为社区贡献1条内容
所有评论(0)