美文网首页工作生活
批量挪同名文件到固定文件夹--标准数据后的处理

批量挪同名文件到固定文件夹--标准数据后的处理

作者: 搬砖程序员 | 来源:发表于2019-07-03 17:57 被阅读0次
# -*- coding:utf-8 -*-
import os
class ImageRename():
    def __init__(self):
        self.path = '/home/utry/image_test/'
    def rename(self):
        filelist = os.listdir(self.path)
        total_num = len(filelist)
        i = 0
        for item in range(299):
            i = item + 1
            i = bytes(i)
            src = self.path + i + '_json/img.png'
            dst = self.path + 'train/'+i+'.png'
            if os.path.exists(src):
                os.rename(src, dst)
                print 'converting %s to %s ...' % (src, dst)
            src = self.path + i + '_json/label.png'
            dst = self.path + 'label/'+i+'_label.png'
            if os.path.exists(src):
                os.rename(src, dst)
                print 'converting %s to %s ...' % (src, dst)
        #print 'total %d to rename & converted %d jpgs' % (total_num, i)
if __name__ == '__main__':
    newname = ImageRename()
    newname.rename()

没了,看这个print 就是python2 python3会报错

相关文章

网友评论

    本文标题:批量挪同名文件到固定文件夹--标准数据后的处理

    本文链接:https://www.haomeiwen.com/subject/nlvchctx.html