Determine the category of a file based on its extension. Args: file_ext: File extension (e.g., ".txt"). Returns: Category name (e.g., "Documents") or "Others" if not matched.
(file_ext: str)
| 46 | |
| 47 | |
| 48 | def get_category(file_ext: str) -> str: |
| 49 | """ |
| 50 | Determine the category of a file based on its extension. |
| 51 | |
| 52 | Args: |
| 53 | file_ext: File extension (e.g., ".txt"). |
| 54 | |
| 55 | Returns: |
| 56 | Category name (e.g., "Documents") or "Others" if not matched. |
| 57 | """ |
| 58 | for category, extensions in FILE_CATEGORIES.items(): |
| 59 | if file_ext.lower() in extensions: |
| 60 | return category |
| 61 | return "Others" |
| 62 | |
| 63 | |
| 64 | def organize_files(base_path: str) -> None: |