Source code: #--coding:utf-8--
from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton, QPlainTextEdit, QMessageBox import time import os import shutil import glob
class tidy(): def init(self):
self.window = QMainWindow() self.window.resize(500, 400) self.window.move(300, 300) self.window.setWindowTitle('File finishing small jacket') self.textEdit = QPlainTextEdit(self.window) self.textEdit.setPlaceholderText("Please enter the path where the client needs to organize the file") self.textEdit.move(10, 25) self.textEdit.resize(300, 25) # self.textEdit = QPlainTextEdit(self.window) # self.textEdit.setPlaceholderText("Please enter the path where the file is placed") # self.textEdit.move(10, 75) # self.textEdit.resize(300, 25) self.button = QPushButton('确定', self.window) self.button.move(250, 300) self.button.clicked.connect(self.handleCalc) def handleCalc(self): info = self.textEdit.toPlainText() mkdir_path = os.path.join(info,'file classification') start_time = time.time() if not os.path.exists(mkdir_path): os.mkdir(mkdir_path) file_num = 0 dir_num = 0 for file in glob.glob(f'{info}\*'): print(file) if os.path.isfile(file): filename = os.path.basename(file) if '.' in filename: suffix = filename.split('.')[-1] else: suffix = 'others' if not os.path.exists(f'{mkdir_path}/{suffix}'): os.mkdir(f'{mkdir_path}/{suffix}') dir_num + = 1 shutil.move(file, f'{mkdir_path}/{suffix}') file_num += 1 end_time = time.time() duaration_time = end_time - start_time if dir_num == 0: QMessageBox.about(self.window, 'Finish results', f'''No need to organize, all right? ''' ) else: QMessageBox.about(self.window, 'Finish results', f'Beep Beep crackling, finishing is complete! \n' f'A total of {file_num} files are classified into {dir_num} folders\n' f'Finishing time is {duaration_time} seconds' )
if name == “main”:
app = QApplication([]) stats = tidy() stats.window.show() app.exec_()
Steps: 1. Download the PySide2 library 2. Copy the above code of the blogger 3. Download the pyinstaller library 4. cmd to enter the directory where the py file of the code is located 5. pyinstaller -F -i your file name.py --noconsole 6. In the py file The same level directory will generate the program, and the exe executable file can be found in the dist directory
Effect picture:
Purpose: Mainly used to organize desktop files~ (Organize files in a certain directory~)
postscript
Recently, many friends consulted about Python learning issues through private messages. To facilitate communication, click on the blue to join the discussion and answer resource base by yourself