diff --git a/nodes.py b/nodes.py index 96c7471..115b323 100644 --- a/nodes.py +++ b/nodes.py @@ -11,6 +11,9 @@ class SaveLatentAbsolute: "required": { "samples": ("LATENT",), "path": ("STRING", {"default": "/path/to/latent.latent"}), + }, + "optional": { + "overwrite": ("BOOLEAN", {"default": False}), } } @@ -19,12 +22,19 @@ class SaveLatentAbsolute: CATEGORY = "latent" OUTPUT_NODE = True - def save(self, samples, path): + def save(self, samples, path, overwrite=False): path = os.path.expanduser(path) if not path.endswith(".latent"): path += ".latent" os.makedirs(os.path.dirname(path), exist_ok=True) + if not overwrite and os.path.exists(path): + base, ext = os.path.splitext(path) + counter = 1 + while os.path.exists(f"{base}_{counter}{ext}"): + counter += 1 + path = f"{base}_{counter}{ext}" + tensors = {} non_tensors = {} devices = {}