From 3ecc7b75c89ce82bfe05e169cfef6ce356363cbe Mon Sep 17 00:00:00 2001 From: "pierre.gauthier" Date: Wed, 19 Feb 2025 14:23:59 +0100 Subject: [PATCH] feat : Correct_file_name replace accents in file names --- dory_sort_out.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dory_sort_out.py b/dory_sort_out.py index b15ad4e..3fe140c 100644 --- a/dory_sort_out.py +++ b/dory_sort_out.py @@ -5,6 +5,7 @@ import os import re import glob import shutil +import unicodedata from datetime import datetime import openpyxl as xls @@ -103,8 +104,13 @@ def correct_file_name(file): espaces et tirets deviennent des underscore """ basename = os.path.basename(file) - correct_file = basename.replace(" ","_") - correct_file = basename.replace("-","_") + correct_file = basename.replace(" ","_").replace("-","_") + + # Supprime les accents et les convertis en minuscules + correct_file = ''.join( + (c if unicodedata.category(c) != 'Mn' else '') + for c in unicodedata.normalize('NFD', correct_file) + ) correct_file = os.path.join(os.path.dirname(file),correct_file) os.rename(file,correct_file) return correct_file