Compression dans un zip

This commit is contained in:
Alex 2024-03-19 21:10:41 +01:00
parent 84a34dafa7
commit 250cded180
3 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,5 @@
{
"filigrame": "Le nom de l'agence",
"source_directory": "C:\\Directory\\with\\Oriiginal\\Files"
"filigrame": "Agence la foret",
"zipfile": "I:\\Drive\\Documents\\Logement Maelis",
"source_directory": "H:\\Utilisateurs\\Alex\\Maelis\\Maelis - Logement 2024"
}

17
main.py
View File

@ -16,7 +16,7 @@ Il est conseillé de mettre un chemin absolu.
# Press Maj+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import os, json, subprocess
import os, json, subprocess, zipfile
from PIL import Image, ImageDraw, ImageFont
import piexif
from pdf2image import convert_from_path
@ -161,7 +161,15 @@ def create_original_files_directory():
with open("config.json", "w") as f:
json.dump(config, f, indent=4)
print(f"Sauvegarde de la configuration")
def zip_directory(directory, zip_file):
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
zipf.write(file_path, os.path.relpath(file_path, directory))
if __name__ == '__main__':
# Creation du répertoire soruces pour mettre les documents
create_original_files_directory()
@ -187,3 +195,8 @@ if __name__ == '__main__':
# Ouverture du répertoire contenant toutes les images tagées
open_in_file_explorer(destination_directory)
# Compression du répertoire
fichierZip = os.path.join(config["zipfile"], text.replace(" ", "_") + ".zip")
print("Compression du répertoire et sauvegarde dans ", fichierZip)
zip_directory(destination_directory, fichierZip)

View File

@ -1,3 +1,4 @@
Pillow>=8.4.0
piexif
pdf2image
pdf2image
zipfile