import sys import os from pathlib import Path def process_directory(dir_arg): # Résolution des chemins base_dir = Path(dir_arg) bgnot_dir = base_dir / "BGnot" sync_dir = Path.home() / "SyncCopies" / "À Annoter" / dir_arg # Création du dossier de destination s'il n'existe pas sync_dir.mkdir(parents=True, exist_ok=True) if not bgnot_dir.is_dir(): print(f"Erreur : le sous-dossier {bgnot_dir} n'existe pas.") return # Récupération de tous les sous-dossiers subdirs = [d for d in bgnot_dir.iterdir() if d.is_dir()] if not subdirs: return # Application des règles de sélection all_start_with_copie = all(d.name.startswith("Copie") for d in subdirs) if all_start_with_copie: chosen_dirs = subdirs else: chosen_dirs = [d for d in subdirs if not d.name.startswith("Copie")] # Traitement des dossiers sélectionnés for subdir in chosen_dirs: concat_file = subdir / "Concat.pdf" if not concat_file.is_file(): print(f"Attention : le fichier {concat_file} est introuvable.") continue symlink_path = sync_dir / f"{subdir.name}.pdf" # Supprime le lien précédent s'il existe pour éviter une erreur if symlink_path.is_symlink() or symlink_path.exists(): symlink_path.unlink() # Création du lien symbolique (pointe vers le chemin absolu pour éviter les problèmes) os.link(concat_file.absolute(), symlink_path) if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python script.py