From 3d1e3dd93e1b9d9346a0c0c0990a1567380e6093 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Mon, 2 Feb 2026 18:44:09 +0100 Subject: [PATCH] Add auto-increment on filename conflict with overwrite toggle Co-Authored-By: Claude Opus 4.5 --- nodes.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 = {}