33 lines
907 B
Python
33 lines
907 B
Python
from tkinter.filedialog import askdirectory
|
|
from tkinter import Tk
|
|
import os
|
|
import subprocess
|
|
import hashlib
|
|
from pathlib import Path
|
|
|
|
sevenzip = r"C:\Program Files\7-Zip\7z.exe"
|
|
|
|
# We don't want the GUI window of
|
|
# tkinter to be appearing on our screen
|
|
Tk().withdraw()
|
|
|
|
# Dialog box for selecting a folder.
|
|
file_path = askdirectory(title="Select a folder")
|
|
|
|
# Listing out all the files
|
|
# inside our root folder.
|
|
list_of_files = os.walk(file_path)
|
|
|
|
for root, folders, files in list_of_files:
|
|
|
|
for file in files:
|
|
file_path = Path(os.path.join(root, file))
|
|
name, _ = os.path.splitext(file_path)
|
|
zipped_filename = f"{name}.7z"
|
|
if not os.path.isfile(zipped_filename):
|
|
try:
|
|
subprocess.run([sevenzip, 'a', zipped_filename, file_path], check=True)
|
|
except:
|
|
input("")
|
|
exit()
|