# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_osutils.ipynb.

# %% auto 0
__all__ = ['clean_directory']

# %% ../nbs/01_osutils.ipynb 4
from pathlib import Path
import os
import shutil

# %% ../nbs/01_osutils.ipynb 7
def clean_directory(base_path, keep_items):
    base_path = Path(base_path)
    keep_paths = {base_path / item for item in keep_items}  # Use a set for faster lookup

    for item in base_path.iterdir():
        if item not in keep_paths:
            try:
                if item.is_file() or item.is_symlink():
                    item.unlink()
                elif item.is_dir():
                    shutil.rmtree(item)
            except OSError as e:  # Catching specific OS-related errors
                print(f"Failed to delete {item}: {e}")
