python QT5 面向对象代码 函数不会,帮忙指点改写一下,学习

1、选择文件夹后,点击OK 开始执行,批量转换后缀名为zip,并解压,在次批量改名字为txt
解压的这个过来不显示,最好是隐藏执行,最好是在内存中完成,
2、最后解压出来的文件在批量改为TXT文件,在原目录显示就可以了。
class Win_Main:
def init(self):
self.textEdit = None
self.ui = QUiLoader().load(‘Main.ui’)
self.ui.open.clicked.connect(self.TMI_ULR) #点击先择文件夹按键

    #self.ui.open.setPlaceholderText('请在这里输入URL')   #文本框里面选择文件夹地址

    self.ui.OK.clicked.connect(self.vinkun)#点击开始件  #执行

开始批量转换后缀名为zip,并解压,在次批量改名字为txt
解压的这个过来不显示,最好是隐藏执行,最好是在内存中完成,
2、最后解压出来的文件在批量改为TXT文件,在原目录显示就可以了。
占用论坛资源,还希望学长们帮忙指点一下,帮忙写一下。非常谢谢。
下面代码是我在网上抄的,请见谅。

两个按键button 之间的信号与槽 的建立不是很明白,学长帮忙写一个,虚心求教。

def TMI_ULR(self):   # 选择按钮点击 vin框 显示地址数据
  directory = QtWidgets.QFileDialog.getExistingDirectory(None,"选取多个文件","C:/",)  # 起始路径
   self.ui.vin.setText(directory)
 def vinkun(self):
    # Path = "F:\\test\\"  # windows下的文件目录
    # Path = input("请输入你需要操作的目录(格式如'F:\\test'):")
    #Path = r"E:\hs08-oracle\py\\";
    Path =
    filelist = os.listdir(Path)
    for files in filelist:
        Olddir = os.path.join(Path, files)
        print(files)  # 打印出老的文件夹里的目录和文件
        if os.path.isdir(Olddir):  # 判断是否是文件,是文件,跳过
            continue
        filename = os.path.splitext(files)[0]
        # filetype = os.path.splitext(files)[1]
        # 如果后缀是.dat
        # if filetype == ".txt":
        Newdir = os.path.join(Path, filename + '.sql')  # 只要修改后缀名就可以更改成任意想要的格式
        os.rename(Olddir, Newdir)
讨论数量: 1
Jason990420

Example code for you.

pathlib 路径包

import sys
from pathlib import Path
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFileDialog

class Example(QWidget):

    def __init__(self):

        super().__init__()
        self.init_UI()

    def init_UI(self):

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Directory')

        self.button = QPushButton('目錄', self)
        self.button.resize(self.button.sizeHint())
        self.button.move(50, 50)
        # call self.on_button_click when button clicked
        self.button.clicked.connect(self.on_button_click)

        self.show()

    def on_button_click(self):
        directory = QFileDialog.getExistingDirectory(None,"选取多个文件","C:/",)
        path = Path(directory)
        if path.is_dir():
            for file in path.glob("*.zip"):     # Find all files under directory
                if file.is_file():
                    self.unzip(file)

    def unzip(self, file):
        # unzip file and rename files here, code skipped
        print(file)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    win = Example()
    sys.exit(app.exec_())
2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!