在这里插入图片描述
下面展示一些 代码
。
import os
outer_path = 'D:/**/**/timed/-Z/0.14/'
folderlist = os.listdir(outer_path) # 列举文件夹
for folder in folderlist:
inner_path = os.path.join(outer_path, folder)
total_num_folder = len(folderlist) # 文件夹的总数
print('total have %d folders' % (total_num_folder)) # 打印文件夹的总数
filelist = os.listdir(inner_path) # 列举图片
i = 1
for item in filelist:
total_num_file = len(filelist) # 单个文件夹内图片的总数
if item.endswith('.png'):
src = os.path.join(os.path.abspath(inner_path), item) # 原图的地址
dst = os.path.join(os.path.abspath(inner_path), '000'+ str(
i) + '.png') # 新图的地址
try:
os.rename(src, dst)
print('converting %s to %s ...' % (src, dst))
i += 1
except:
continue
print('total %d to rename & converted %d jpgs' % (total_num_file, i))