码迷,mamicode.com
首页 > 移动开发 > 详细

[記錄用]python py2app 檔案批次重新命名

时间:2016-08-14 07:12:50      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:

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)#使用py2app打包時 相對路徑會更改
#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
001.mp4 002.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按鈕 執行批次重新命名

技术分享

技术分享

 

[記錄用]python py2app 檔案批次重新命名

标签:

原文地址:http://www.cnblogs.com/copy0401/p/5769252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!