Compression dans un zip
This commit is contained in:
parent
84a34dafa7
commit
250cded180
@ -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
17
main.py
@ -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)
|
||||
|
@ -1,3 +1,4 @@
|
||||
Pillow>=8.4.0
|
||||
piexif
|
||||
pdf2image
|
||||
pdf2image
|
||||
zipfile
|
Loading…
Reference in New Issue
Block a user