
首先确保自己电脑安装了python语言,并且配置好python。我使用的是python3.6.5版本
开发工具PyCharm2018.2.3
1.python的简单使用
使用python语言,学习使用python的基本语法。
def rename(self,event):
i = 0;
Newdir=''
path = self.path_text.GetValue()
prefix=self.prefix_text.GetValue()
pretype=self.pretype_text.GetValue()
print(path=='')
if(path=='' or prefix==''):
wx.MessageBox('文件路径或文件前缀为空','Info',wx.OK|wx.ICON_INFORMATION)
exit
filelist = os.listdir(path)
for files in filelist:
i = i + 1
Olddir = os.path.join(path, files)
if (os.path.isdir(Olddir)):
continue;
filename = os.path.splitext(files)[0]
filetype = os.path.splitext(files)[1]
if(pretype!=""):
Newdir= os.path.join(path, prefix + str(i) + '.'+pretype)
else:
Newdir = os.path.join(path, prefix + str(i) + filetype)
os.rename(Olddir, Newdir)
self.file_newlist_txt.Clear()
self.file_newlist_txt.Append(self.traverse_file())
2.python wxpython GUI编程初步
在cmd窗口执行
pip install wxpython
安装wxpython,否则在import wx时会报错
wxpython,基本控件textCtrl ,button,Dialog
class MyFrame(wx.Frame):
def __init__(self,parent,id=wx.ID_ANY,title="",
pos=(1000,200),size=(600,500),
style=wx.DEFAULT_FRAME_STYLE,
name="MyFrame"):
super(MyFrame,self).__init__(parent,id,title,pos,size,style,name)
#属性
self.panel=wx.Panel(self)
#增加控件
self.path_text=wx.TextCtrl(self.panel,pos=(20,20),size=(350,24))
self.open_button=wx.Button(self.panel,label="浏览文件",pos=(380,20),size=(70,24))
self.prefix_txt=wx.StaticText(self.panel,label="文件前缀",pos=(20,60),style=wx.ALIGN_CENTER)
self.pretype_txt=wx.StaticText(self.panel,label="文件类型",pos=(200,60),style=wx.ALIGN_CENTER)
self.prefix_text=wx.TextCtrl(self.panel,pos=(20,80),size=(150,24))
self.pretype_text=wx.TextCtrl(self.panel,pos=(200,80),size=(150,24))
self.modify_button=wx.Button(self.panel,label="确认修改",pos=(380,80),size=(70,24))
self.file_list_txt=wx.ListBox(self.panel,pos=(20,120),size=(200,300),style=wx.LB_SINGLE)
self.file_newlist_txt=wx.ListBox(self.panel,pos=(340,120),size=(200,300),style=wx.LB_SINGLE)
#事件处理函数
self.Bind(wx.EVT_BUTTON,self.open_floder,self.open_button)
self.Bind(wx.EVT_BUTTON,self.rename,self.modify_button)
#self.panel.Bind(wx.EVT_ERASE_BACKGROUND,self.OnEraseBackground)
3.py脚本打包成可执行的.exe文件
安装pyinstaller:pip install pyinstaller
采用pyinstaller将py脚本打包成exe,并且去除黑色cmd窗口。
pyinstaller -F ReNameFile.py --noconsole
或者
pyinstaller -F -w ReNameFile.py
批量命名工具 下载地址
https://download.youkuaiyun.com/download/chentao1215/10847616