Skip to content

Commit

Permalink
Merge pull request #2156 from h-mayorquin/add_overwrite_to_save_to_fo…
Browse files Browse the repository at this point in the history
…lder

Add overwrite option to save to folder
  • Loading branch information
alejoe91 authored Nov 3, 2023
2 parents a0712e7 + ba908a5 commit d92ae92
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/spikeinterface/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
-------
Expand All @@ -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
Expand Down

0 comments on commit d92ae92

Please sign in to comment.