The specific code of python batch naming photos for your reference, the specific content is as follows
Not much nonsense, the renderings
All codes
from tkinter import*import os
# Add folder path
def rename():
path =entry.get()
filelist = os.listdir(path) #Get file path
total_num =len(filelist) #Get file length (number)
i =1 #Indicates that the naming of the file starts from 1
for item in filelist:if item.endswith('.jpg'): #The format of the initial picture is jpg format
src = os.path.join(os.path.abspath(path), item)
dst = os.path.join(os.path.abspath(path),''+str(i)+'.jpg')#Naming rules after processing
try:
os.rename(src, dst)
# print('converting %s to %s ...'%(src, dst))
text.insert(END,'First%s Zhang was named successfully!...'%i)
i = i +1
except:continue
text.insert(END,'All naming is complete!...')
root =Tk()
root.title("Photo Batch Namer")
root.geometry("450x300")
root.minsize(450,300)
root.maxsize(450,300)
label =Label(root, text="Folder path:", font=('Microsoft Yahei',15))
label.grid(row=0,column=0)
entry =Entry(root, font=('Microsoft Yahei',15))
entry.grid(row=0, column=1)
text =Listbox(root, font=("Microsoft Yahei",15), width=37, height=8)
text.grid(row=1, columnspan=2)
button =Button(root, text="Start", font=("Microsoft Yahei",13),command=rename)
button.grid(row=2, column=0,sticky=W)
button1 =Button(root, text="drop out", font=("Microsoft Yahei",13),command=quit)
button1.grid(row=2, column=1, sticky=E)mainloop()
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts