Remove all directories matching the pattern. Args: root: Root directory to search from pattern: Directory name pattern to match Returns: Number of directories removed
(root: Path, pattern: str)
| 43 | |
| 44 | |
| 45 | def remove_directories(root: Path, pattern: str) -> int: |
| 46 | """ |
| 47 | Remove all directories matching the pattern. |
| 48 | |
| 49 | Args: |
| 50 | root: Root directory to search from |
| 51 | pattern: Directory name pattern to match |
| 52 | |
| 53 | Returns: |
| 54 | Number of directories removed |
| 55 | """ |
| 56 | count = 0 |
| 57 | for dirpath in root.rglob(pattern): |
| 58 | if dirpath.is_dir(): |
| 59 | try: |
| 60 | shutil.rmtree(dirpath) |
| 61 | count += 1 |
| 62 | except (OSError, PermissionError) as e: |
| 63 | print(f"{Colors.RED}Warning: Could not remove {dirpath}: {e}{Colors.NC}") |
| 64 | return count |
| 65 | |
| 66 | |
| 67 | def remove_files(root: Path, pattern: str) -> int: |