From 6832b052306517a2b196c219e0b8ff2d4ccbb217 Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Wed, 11 Sep 2024 04:15:40 +0200 Subject: [PATCH] [+] filter_directory_content Allows a user to extract the files having a specific extension --- file_manager.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/file_manager.py b/file_manager.py index f31af0c..9b0f400 100644 --- a/file_manager.py +++ b/file_manager.py @@ -2,8 +2,8 @@ import datetime import json import logging import os -import shutil import re +import shutil supported_versions = ["bukkit", "paper", "spigot"] @@ -102,6 +102,15 @@ def get_path_from_extension(filename) -> str or None: return None +def filter_directory_contents(desired_extension: str, directory_contents: list[str]): + filtered_list = [] + for item in directory_contents: + _, ext = os.path.splitext(item) + if ext.lower() == desired_extension: + filtered_list.append(item) + return filtered_list + + def kebab_to_camel_case(s: str) -> str: parts = s.split('-') return parts[0] + ''.join(part.title() for part in parts[1:])