#生成13位随机码作为新的文件名 import string import random def newname_creator(digit): newname='' for word in range(digit): newname+=random.choice(string.ascii_uppercase + string.digits) return newname def all_newname(): data='' count=0 for count in range(358): digit=13 data+=newname_creator(digit)+'.jpg'+'\n' return data f=open('newname.txt','w') f.write(all_newname()) f.close() #批量重命名
newnames=open('newname.txt','r+') newnames=list(newnames) file_names=os.listdir('E:/wallpaper') index=0 for index in range(358): os.rename('E:/wallpaper/'+file_names[index],'E:/wallpaper/'+newnames[index].strip('\n'))