MCPcopy Create free account
hub / github.com/ForeignGods/ComfyUI-Mana-Nodes / construct_text_path

Method construct_text_path

nodes/string2file_node.py:47–67  ·  view source on GitHub ↗
(self, kwargs)

Source from the content-addressed store, hash-verified

45 return {"ui": {"text": string}, "result": (string,)}
46
47 def construct_text_path(self, kwargs):
48 base_directory = folder_paths.get_output_directory()
49 filename_prefix = os.path.normpath(kwargs['filename_prefix'][0])
50 full_path = os.path.join(base_directory, filename_prefix)
51
52 # Ensure the path ends with .mp4
53 if not full_path.endswith('.txt'):
54 full_path += '.txt'
55
56 # Increment filename if it already exists
57 counter = 1
58 while os.path.exists(full_path):
59 # Construct a new path with an incremented number
60 new_filename = f"{filename_prefix}_{counter}.txt"
61 full_path = os.path.join(base_directory, new_filename)
62 counter += 1
63
64 # Create the directory if it does not exist
65 Path(os.path.dirname(full_path)).mkdir(parents=True, exist_ok=True)
66
67 return full_path

Callers 1

runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected