Clean up a directory by removing its contents. Args: path: Directory to clean keep_hidden: Keep hidden files/directories (starting with .) Raises: FileSystemError: If cleanup fails
(path: Path, keep_hidden: bool = True)
| 161 | |
| 162 | |
| 163 | def cleanup_directory(path: Path, keep_hidden: bool = True): |
| 164 | """ |
| 165 | Clean up a directory by removing its contents. |
| 166 | |
| 167 | Args: |
| 168 | path: Directory to clean |
| 169 | keep_hidden: Keep hidden files/directories (starting with .) |
| 170 | |
| 171 | Raises: |
| 172 | FileSystemError: If cleanup fails |
| 173 | """ |
| 174 | path = Path(path).expanduser().resolve() |
| 175 | |
| 176 | if not path.exists(): |
| 177 | return |
| 178 | |
| 179 | try: |
| 180 | for item in path.iterdir(): |
| 181 | if keep_hidden and item.name.startswith('.'): |
| 182 | continue |
| 183 | |
| 184 | if item.is_file(): |
| 185 | item.unlink() |
| 186 | elif item.is_dir(): |
| 187 | shutil.rmtree(item) |
| 188 | except Exception as e: |
| 189 | raise FileSystemError(f"Cannot clean directory {path}: {e}") |
| 190 |
nothing calls this directly
no test coverage detected