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ファイルシュレッダー

crush.py

import tkinter as tk
from tkinter import ttk
import os
import windnd
from threading import Thread
import shutil

root = tk.Tk()
root.title("ファイル粉砕機")
root.geometry("612x288")
root.resizable(False, False)
root.iconbitmap("icon.ico")

# カスタムフォント
font_style = "Courier New"

# label_warning、label_volume、text、btn_executeなどのコンポーネントを作成してレイアウト

label_warning = tk.Label(root, text="注意:ファイルを粉砕する前に関連するファイルやプログラムを閉じてください。そうしないとエラーが発生する可能性があります。", foreground="red", font=(font_style, 12, "bold"))
label_warning.pack()

label_volume = tk.Label(root, text="ファイル数:0\tフォルダ数:0\t総データ:0\n実行成功:0\t異常ファイル:0", font=(font_style, 12))
label_volume.pack(pady=20)

text = tk.Text(root, width=84, height=6, font=(font_style, 12), bg="#EFEFEF")
text.pack(padx=10, pady=10)
text.insert("insert", "粉砕するファイルをここにドラッグしてください!")
text.configure(state="disabled")

files_A = []
folder_A = []
folder_B = []
G = []

def handle_drag(files):
    global files_A, folder_A, folder_B, G
    files_A = []
    folder_A = []
    folder_B = []
    G = []

    text.configure(state="normal")
    text.delete("1.0", "end")

    for file in files:
        file = file.decode("gbk")
        if os.path.isfile(file):
            text.insert("insert", file.replace("\\", "/") + "\n")
            files_A.append(file.replace("\\", "/"))
        else:
            folder_A.append(file)

    for folder in folder_A:
        for a in os.walk(folder.replace("\\", "/")):
            folder_B = [a[0].replace("\\", "/")] + folder_B
            for file in a[2]:
                text.insert("insert", os.path.join(a[0], file).replace("\\", "/") + "\n")
                files_A.append(os.path.join(a[0], file).replace("\\", "/"))

    for folder in folder_B:
        text.insert("insert", folder + "\n")

    label_volume.config(text=f"ファイル数:{len(files_A)}\tフォルダ数:{len(folder_B)}\t総データ:{len(files_A)+len(folder_B)}\n実行成功:0\t異常ファイル:0")
    text.configure(state="disabled")


def delete_file(file):
    global G
    if os.path.isfile(file):
        try:
            with open(file, "w") as f:
                f.write("1")
            os.remove(file)
            text.configure(state="normal")
            text.insert("insert", "· 処理完了 >>" + file + "\n")
            text.see(tk.END)
            text.configure(state="disabled")
        except:
            try:
                os.remove(file)
            except:
                G.append("【異常未処理】 >>" + file)
    else:
        G.append("【異常未処理】 >>" + file)


def delete_folder(folder):
    global G
    if os.path.isfile(folder) == False:
        if os.path.exists(folder):
            try:
                shutil.rmtree(folder)
                text.configure(state="normal")
                text.insert("insert", "· 処理完了 >>" + folder + "\n")
                text.see(tk.END)
                text.configure(state="disabled")
            except:
                G.append("【異常未処理】 >>" + folder)
        else:
            G.append("【異常未処理】 >>" + folder)
    else:
        G.append("【異常未処理】 >>" + folder)


def execute():
    def task():
        global folder_B
        if btn_execute["state"] == "disabled":
            return
        else:
            text.configure(state="normal")
            text.delete("1.0", "end")
            text.configure(state="disabled")
            btn_execute["state"] = "disabled"

            for file in files_A:
                delete_file(file)

            for folder in folder_B:
                delete_folder(folder)

            for item in G:
                text.configure(state="normal")
                text.insert("insert", f"{item}\n")
                text.see(tk.END)
                text.configure(state="disabled")

            label_volume.config(text=f"ファイル数:{len(files_A)}\tフォルダ数:{len(folder_B)}\t総データ:{len(files_A)+len(folder_B)}\n実行成功:{len(files_A)+len(folder_B)-len(G)}\t異常ファイル:{len(G)}")
            btn_execute["state"] = "normal"

    Thread(target=task).start()

btn_execute = tk.Button(root, text="一括粉砕", width=20, command=execute, font=(font_style, 12), foreground="#FFFFFF", background="#0055FF")
btn_execute.pack(pady=10)


windnd.hook_dropfiles(root, func=handle_drag)

# カスタムボタンスタイル
style = ttk.Style()
style.configure("Custom.TButton", font=(font_style, 12), foreground="#FFFFFF", background="#0055FF", padding=8)

root.mainloop()

ファイルをウィンドウにドラッグして、一括粉砕できます。

image

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。