效果如下:0001号用户的第 i 张图片
代码:
import osclass ImageRename():def __init__(self):self.path = 'C:/Users/lbpeng/Desktop/test/chictopia2/images1/fashioninmysoul/full'def rename(self):filelist = os.listdir(self.path)totalnum = len(filelist)i = 1for item in filelist:if item.endswith('.jpg'):src = os.path.join(os.path.abspath(self.path), item)dst = os.path.join(os.path.abspath(self.path), '0001' + format(str(i), '0>3s') + '.jpg')os.rename(src, dst)i = i + 1if __name__ == '__main__':newname = ImageRename()newname.rename()