diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index b51bace55f..1a8674697a 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -788,7 +788,7 @@ def save_to_memory(self, **kwargs) -> "BaseExtractor": return cached # TODO rename to saveto_binary_folder - def save_to_folder(self, name=None, folder=None, verbose=True, **save_kwargs): + def save_to_folder(self, name=None, folder=None, overwrite=False, verbose=True, **save_kwargs): """ Save extractor to folder. @@ -819,6 +819,8 @@ def save_to_folder(self, name=None, folder=None, verbose=True, **save_kwargs): folder: None str or Path Name of the folder. If "folder" is given, "name" must be None. + overwrite: bool, default: False + If True, the folder is removed if it already exists Returns ------- @@ -839,7 +841,12 @@ def save_to_folder(self, name=None, folder=None, verbose=True, **save_kwargs): print(f"Use cache_folder={folder}") else: folder = Path(folder) - assert not folder.exists(), f"folder {folder} already exists, choose another name" + if overwrite and folder.is_dir(): + import shutil + + shutil.rmtree(folder) + + assert not folder.exists(), f"folder {folder} already exists, choose another name or use overwrite=True" folder.mkdir(parents=True, exist_ok=False) # dump provenance