import os class BatchJpg(): def __init__(self): self.pathf = "D:\pycharm_save\class\class\class17" def rename(self): files = os.listdir(self.pathf) # 打开路径下的内容 Length = len(files) i = 0 for fileser in files: # 将pathf路径下的文件遍历到fileser中 if fileser.endswith('.jpg'): # 如果尾缀为jpg start = os.path.join(os.path.abspath(self.pathf), fileser) # 获取文件中的内容 s = str(i) s = s.zfill(8) # 将s重置成八位数 end = os.path.join(os.path.abspath(self.pathf), s + '.jpg') try: os.rename(start, end) # 名称转换 i += 1 except: continue print("总共有%d文件,共重置名称%d个" % (Length, i)) if __name__ == '__main__': demo = BatchJpg() demo.rename()
python读取文档图片并进行名称的修改
最新推荐文章于 2023-06-16 10:01:03 发布