From 46156f7bdde2f974285473e35684306e7c60103c Mon Sep 17 00:00:00 2001 From: Matt Troutman Date: Wed, 2 Oct 2024 16:27:49 -0500 Subject: [PATCH] refactoring a bit --- .fontfoldercleanup/font_folder_cleanup.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.fontfoldercleanup/font_folder_cleanup.py b/.fontfoldercleanup/font_folder_cleanup.py index 6a91e60..8e1fee1 100644 --- a/.fontfoldercleanup/font_folder_cleanup.py +++ b/.fontfoldercleanup/font_folder_cleanup.py @@ -264,7 +264,8 @@ def dont_use_dots_for_font_files(root_path=font_location): for root, dirs, files in os.walk(root_path): for file in files: file_path = os.path.join(root, file) - if file_path.endswith('.otf') or file_path.endswith('.ttf') or file_path.endswith('.ttc') or file_path.endswith('.pdf'): + extensions = ['.otf', '.ttf', '.ttc', '.pdf', '.woff', '.woff2'] + if any(file_path.endswith(ext) for ext in extensions): new_file_path = None for x in ['.','_', ' ', '-', '.-','--']: if file.startswith(x): @@ -276,6 +277,20 @@ def dont_use_dots_for_font_files(root_path=font_location): print(f"Skipped renaming {file_path} as {new_file_path} already exists") new_file_path = None +def remove_double_and_triple_dashes(root_path=font_location): + ## remove double and triple dashes from file names + ## should loop until no more double or triple dashes are found + for root, dirs, files in os.walk(root_path): + for file in files: + file_path = os.path.join(root, file) + #replace -- or --- with - + if '--' in file or '---' in file: + new_file = file.replace('--','-') + new_file = new_file.replace('---','-') + new_file_path = os.path.join(root, new_file) + os.rename(file_path, new_file_path) + print(f"Renamed file: {file_path} -> {new_file_path}") + if __name__ == '__main__': remove_ds_store_files() remove_empty_folders() @@ -286,5 +301,7 @@ if __name__ == '__main__': lowercase_and_dash_file_names() prepend_folder_name_to_font_dash() dont_use_dots_for_font_files() + remove_double_and_triple_dashes() + remove_double_and_triple_dashes() remove_ds_store_files() remove_empty_folders()