demo.py 主要作用為
將同目錄下 *.mp4 檔案批次重新命名
例如:
aaa001.mp4 ---重新命名為--> 001.mp4
aaa002.mp4 ---重新命名為--> 002.mp4
#!/usr/local/bin/python
# -*- coding: UTF-8 -*- from Tkinter import *
import sys,glob,os
reload(sys)
sys.setdefaultencoding("utf-8") class HelloApp(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.createWidgets()
self.count=0 def createWidgets(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) def run(self):
allfiles = glob.glob(r'../../../*.mp4')
#allfiles = glob.glob(r'*.mp4')
self.text["text"] = '執行開始'
listname = ''
for afile in allfiles:
listname=listname + "," + afile
new_filename = afile.replace('aaa', "")#print afile
os.rename(afile, new_filename)
self.text["text"] = '執行完成' + listname if __name__ == '__main__':
root = Tk()
root.wm_title("imooc rename tool")
#root.maxsize(800, 600)
root.geometry('400x300')
#root.resizable(width=True, height=True)
app = HelloApp(master=root)
app.mainloop()
>py2applet --make-setup demo.py
Existing setup.py detected, replace? [Y/n] y
Wrote setup.py >ls
aaa001.mp4 aaa002.mp4 demo.py setup.py >python setup.py py2app .
.
.
Done!
>ls
aaa001.mp4 aaa002.mp4 build demo.py dist setup.py >ls ./dist
demo.app >ls
aaa001.mp4 aaa.mp4 build demo.py dist setup.py >cp -r ./dist/demo.app ./
>ls
aaa001.mp4 aaa002.mp4 build demo.app demo.py dist setup.py
執行 demo.app
點選 RUN按鈕 執行批次重新命名