파일 처리

2021. 3. 27. 12:25파이썬

    images = Trained_Image.objects.all()
    for i,image in enumerate(images) :
        fileName,ext = os.path.splitext(image.file) 
        dir = os.path.dirname(image.file)
        oldFile = image.file
        image.file = '%s/%s%s' %(dir,i,ext)
        image.box_file = '%s/%s.box' %(dir,i)
        image.tr_file = '%s/%s.tr' %(dir,i)
        image.prefix = '%s/%s' %(dir,i)
        image.save()
        print(oldFile,image.file,image.box_file,image.tr_file,image.prefix)
        os.rename(oldFile,image.file)