import os,sys path = "D:/ps-pdf2/" # 获取该目录下所有文件,存入列表中 fileList = os.listdir(path) n=11 while n<99 : oldname = "PyQt5快速开发与实战电子书-" + str(n + 1) + ".jpg" newname = "PyQt5快速开发与实战电子书-" + "0" + str(n + 1) + ".jpg" oldname2 = path + oldname newname2 = path + newname os.rename(oldname2, newname2) print(oldname2, newname2) n+=1