Remove all files matching the pattern. Args: root: Root directory to search from pattern: File name pattern to match Returns: Number of files removed
(root: Path, pattern: str)
| 65 | |
| 66 | |
| 67 | def remove_files(root: Path, pattern: str) -> int: |
| 68 | """ |
| 69 | Remove all files matching the pattern. |
| 70 | |
| 71 | Args: |
| 72 | root: Root directory to search from |
| 73 | pattern: File name pattern to match |
| 74 | |
| 75 | Returns: |
| 76 | Number of files removed |
| 77 | """ |
| 78 | count = 0 |
| 79 | for filepath in root.rglob(pattern): |
| 80 | if filepath.is_file(): |
| 81 | try: |
| 82 | filepath.unlink() |
| 83 | count += 1 |
| 84 | except (OSError, PermissionError) as e: |
| 85 | print(f"{Colors.RED}Warning: Could not remove {filepath}: {e}{Colors.NC}") |
| 86 | return count |
| 87 | |
| 88 | |
| 89 | def clean_cache() -> List[Tuple[str, int]]: |