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": {
|
"required": {
|
||||||
"samples": ("LATENT",),
|
"samples": ("LATENT",),
|
||||||
"path": ("STRING", {"default": "/path/to/latent.latent"}),
|
"path": ("STRING", {"default": "/path/to/latent.latent"}),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"overwrite": ("BOOLEAN", {"default": False}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,12 +22,19 @@ class SaveLatentAbsolute:
|
|||||||
CATEGORY = "latent"
|
CATEGORY = "latent"
|
||||||
OUTPUT_NODE = True
|
OUTPUT_NODE = True
|
||||||
|
|
||||||
def save(self, samples, path):
|
def save(self, samples, path, overwrite=False):
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
if not path.endswith(".latent"):
|
if not path.endswith(".latent"):
|
||||||
path += ".latent"
|
path += ".latent"
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
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 = {}
|
tensors = {}
|
||||||
non_tensors = {}
|
non_tensors = {}
|
||||||
devices = {}
|
devices = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user