banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

Python file shredder

First, necessary libraries are imported, including tkinter, ttk, os, windnd, and shutil. Then a root window object named "root" is created and its title, size, resizable property, and icon are set.

Next, a custom font style named "font_style" is defined, and several interface components are created, including label_warning (used to display warning messages), label_volume (used to display file count and execution results), text (used to display file paths), and btn_execute (used to execute the file crushing operation).

In the handle_drag function, the logic for handling dragged files is defined. It first clears the content of the text widget, then iterates through the dragged file list and adds the file paths to the files_A list. If a folder is dragged, its path is also added to the folder_A list, and all files within the folder are iterated through and their paths are added to the files_A list. Finally, the folder path is added to the folder_B list, and the file and folder paths are displayed in the text widget.

In the delete_file function, the logic for deleting files is defined. If the file exists, it tries to open the file in write mode and write a character to it, then deletes the file. If the deletion fails, the file path is added to the G list.

In the delete_folder function, the logic for deleting folders is defined. If the folder does not exist, its path is directly added to the G list. If the folder exists, it tries to recursively delete the folder. If the deletion fails, the folder path is added to the G list.

In the execute function, the logic for executing the file crushing operation is defined. It first disables the btn_execute button and clears the content of the text widget. Then it iterates through the files_A list and calls the delete_file function to delete the files. It then iterates through the folder_B list and calls the delete_folder function to delete the folders. Finally, it displays the information of the exception files in the G list in the text widget and updates the text of the label_volume. Finally, it enables the btn_execute button again.

Lastly, the handle_drag function is set as the handler for dropped files, and the main event loop is started with root.mainloop().

Drag the files to be crushed into the window, and click the "一键粉碎" button to start the crushing process.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.