一、代码
import PySimpleGUI as sg
import os
def nameAll(path, key, replace):
filelist=os.listdir(path)
for files in filelist:
old_dir = os.path.join(path, files)
new_file = files.replace(key, replace)
new_dir = os.path.join(path, new_file)
if files.find(key) > -1:
os.rename(old_dir, new_dir)
layout = [[sg.Text('路径'), sg.InputText(size=(15,))],
[sg.Text('关键字'), sg.InputText(size=(15,))],
[sg.Text('替换字符'), sg.InputText(size=(15,))],
[sg.Button('全部替换', key='submit')],
[sg.Quit('退出', key='q')]]
window = sg.Window('批量文件关键字去除', layout, font='微软雅黑')
while True:
event, value = window.Read()
if event == 'submit':
nameAll(value[0], value[1], value[2])
sg.popup_ok('替换成功!')
elif event == 'q':
break
if event == "Exit" or event == sg.WIN_CLOSED:
break
window.close()
二、打包
#基本打包----但是启动exe会带上命令行
#仅仅生成一个文件,不暴露其他信息,启动较慢。
pyinstaller -F xxx.py
# 去命令行打包
pyinstaller -F xxx.pyw
#(生成一个文件夹,里面是多文件模式,启动快。)
pyinstaller -D xxx.pyw
代码放置在gitee
,仓库地址:https://gitee.com/lwstudy/my-py