Add auto-increment on filename conflict with overwrite toggle
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
12
nodes.py
12
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 = {}
|
||||
|
||||
Reference in New Issue
Block a user