效果如下:0001号用户的第 i 张图片

利用Python对文件进行批量重命名——以图片文件为例

代码:

import os


class 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 = 1

        for 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 + 1


if __name__ == '__main__':
    newname = ImageRename()
    newname.rename()

  

 

相关文章:

  • 2021-11-13
  • 2021-07-22
  • 2021-05-29
  • 2021-06-18
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-31
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
相关资源
相似解决方案