demo.py mainly acts as
Rename the *.mp4 file batch under the same catalogue
For example:
Aaa001.mp4-001.mp4
Aaa002.mp4-002.mp4
#!/usr/local/bin/python#-*-coding:utf-8-*- fromTkinterImport*Importsys,glob,osreload (SYS) sys.setdefaultencoding ("Utf-8")classHelloApp (Frame):def __init__(Self, master=None): Frame.__init__(self, Master) Self.grid () self.createwidgets () Self.count=0defcreatewidgets (self): self. QUIT=Button (self) self. quit["text"] ="QUIT"Self . quit["Command"] =self.quit Self. Quit.grid (Row=0, column=0) Self.hi=Button (self) self.hi["text"] ="RUN"self.hi["Command"] =self.run self.hi.grid (Row=0, Column=1) Self.text=Label (self) self.text["text"] =""Self.text.grid (Row=1, column=0,columnspan=2) defRun (self): Allfiles= Glob.glob (r'.. /.. /.. /*.mp4')#使用py2app打包時 Relative path changes
#allfiles = Glob.glob (R ' *.mp4 ')self.text["text"] =' start to execute.'ListName="' forAfileinchAllfiles:listname=listname +","+afile New_filename= Afile.replace ('AAA',"") #Print Afileos.rename (Afile, new_filename) self.text["text"] =' Execute done'+ListNameif __name__=='__main__': Root=Tk () root.wm_title ("IMOOC Rename Tool") #root.maxsize (+)Root.geometry ('400x300') #root.resizable (width=true, height=true)App = HelloApp (master=root) app.mainloop ()
>Py2applet--Make- setup demo.pyExisting setup.py detected, replace? [y/N] ywrote setup.py>lsaaa001.mp4 aaa002.mp4 demo.py setup.py > python setup.py py2app... Done!>lsaaa001.mp4 aaa002.mp4 build demo.py Dist setup.py>ls./DistDemo.app >ls001. mp4002. mp4 Build demo.py Dist setup.py> CP -R./dist/demo.app./>lsaaa001.mp4 aaa002.mp4 Build demo.app demo.py Dist setup.py
Execute demo.app.
Click the Run button to rename the batch.
[Records renamed with]python Py2app file batch