feat : Correct_file_name replace accents in file names
This commit is contained in:
parent
3ecb096271
commit
3ecc7b75c8
@ -5,6 +5,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import glob
|
import glob
|
||||||
import shutil
|
import shutil
|
||||||
|
import unicodedata
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import openpyxl as xls
|
import openpyxl as xls
|
||||||
|
|
||||||
@ -103,8 +104,13 @@ def correct_file_name(file):
|
|||||||
espaces et tirets deviennent des underscore
|
espaces et tirets deviennent des underscore
|
||||||
"""
|
"""
|
||||||
basename = os.path.basename(file)
|
basename = os.path.basename(file)
|
||||||
correct_file = basename.replace(" ","_")
|
correct_file = basename.replace(" ","_").replace("-","_")
|
||||||
correct_file = basename.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)
|
correct_file = os.path.join(os.path.dirname(file),correct_file)
|
||||||
os.rename(file,correct_file)
|
os.rename(file,correct_file)
|
||||||
return correct_file
|
return correct_file
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user