LocalFolderArchiver:利用7z技術,革新嘅文件加密同分割方案

提示: 作者被禁止或刪除 內容自動屏蔽

提示: 作者被禁止或刪除 內容自動屏蔽

TOP

  1. import os
  2. import shutil
  3. import py7zr
  4. import datetime
  5. import tkinter as tk
  6. from tkinter import filedialog
  7. from tkinter import messagebox

  8. def split_folder(folder_path, max_size):
  9.     files = os.listdir(folder_path)
  10.     current_folder = None
  11.     current_size = 0
  12.     folder_index = 1

  13.     for file_name in files:
  14.         file_path = os.path.join(folder_path, file_name)
  15.         if os.path.isfile(file_path):
  16.             if current_folder is None or current_size + os.path.getsize(file_path) > max_size:
  17.                 current_folder = os.path.join(folder_path, f"folder_{folder_index}")
  18.                 os.mkdir(current_folder)
  19.                 folder_index += 1
  20.                 current_size = 0

  21.             shutil.move(file_path, current_folder)
  22.             current_size += os.path.getsize(os.path.join(current_folder, file_name))

  23. def encrypt_file(file_path, password):
  24.     archive_path = file_path + ".7z"
  25.     with py7zr.SevenZipFile(archive_path, 'w', password=password) as archive:
  26.         archive.writeall(file_path, os.path.basename(file_path))
  27.     os.remove(file_path)
  28.     os.rename(archive_path, file_path)

  29. def decrypt_file(file_path, password):
  30.     archive_path = file_path + ".7z"
  31.     os.rename(file_path, archive_path)
  32.     with py7zr.SevenZipFile(archive_path, 'r', password=password) as archive:
  33.         archive.extractall(path=os.path.dirname(file_path))
  34.     os.remove(archive_path)

  35. def add_password_hint(file_path, password_hint):
  36.     new_file_name = f"{os.path.splitext(file_path)[0]} [{password_hint}]{os.path.splitext(file_path)[1]}"
  37.     os.rename(file_path, new_file_name)

  38. def add_timestamp(file_path):
  39.     timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
  40.     new_file_name = f"{os.path.splitext(file_path)[0]} [{timestamp}]{os.path.splitext(file_path)[1]}"
  41.     os.rename(file_path, new_file_name)

  42. def browse_folder():
  43.     folder_path = filedialog.askdirectory()
  44.     folder_path_entry.delete(0, tk.END)
  45.     folder_path_entry.insert(tk.END, folder_path)

  46. def process_folder():
  47.     folder_path = folder_path_entry.get()
  48.     max_size = int(max_size_entry.get())
  49.     password = password_entry.get()
  50.     password_hint = password_hint_entry.get()

  51.     split_folder(folder_path, max_size)

  52.     for file_name in os.listdir(folder_path):
  53.         file_path = os.path.join(folder_path, file_name)
  54.         encrypt_file(file_path, password)
  55.         add_password_hint(file_path, password_hint)
  56.         add_timestamp(file_path)

  57.     messagebox.showinfo("Done", "Processing complete!")

  58. window = tk.Tk()
  59. window.title("File Management Tool")

  60. folder_path_label = tk.Label(window, text="Folder Path:")
  61. folder_path_label.grid(row=0, column=0, padx=10, pady=5)

  62. folder_path_entry = tk.Entry(window, width=50)
  63. folder_path_entry.grid(row=0, column=1, padx=10, pady=5)

  64. browse_button = tk.Button(window, text="Browse", command=browse_folder)
  65. browse_button.grid(row=0, column=2, padx=10, pady=5)

  66. max_size_label = tk.Label(window, text="Max Size (bytes):")
  67. max_size_label.grid(row=1, column=0, padx=10, pady=5)

  68. max_size_entry = tk.Entry(window, width=20)
  69. max_size_entry.grid(row=1, column=1, padx=10, pady=5)

  70. password_label = tk.Label(window, text="Password:")
  71. password_label.grid(row=2, column=0, padx=10, pady=5)

  72. password_entry = tk.Entry(window, width=20)
  73. password_entry.grid(row=2, column=1, padx=10, pady=5)

  74. password_hint_label = tk.Label(window, text="Password Hint:")
  75. password_hint_label.grid(row=3, column=0, padx=10, pady=5)

  76. password_hint_entry = tk.Entry(window, width=20)
  77. password_hint_entry.grid(row=3, column=1, padx=10, pady=5)

  78. process_button = tk.Button(window, text="Process", command=process_folder)
  79. process_button.grid(row=4, column=0, columnspan=3, padx=10, pady=5)

  80. window.mainloop()
複製代碼
開源的,點用自便

TOP

唔知係咪認真咗,啲文筆咁似ChatGPT寫

不過即係咁,你出咁多post 一條 download link 都冇係咩玩法,雖然我都唔用

TOP

提示: 作者被禁止或刪除 內容自動屏蔽

TOP