`%date:yyyy-MM-dd%` doesn't work when passed in from an external PrimitiveString
Custom Node Testing
- [ ] I have tried disabling custom nodes and the issue persists (see how to disable custom nodes if you need help)
Expected Behavior
The %% field is replaced with the correct string before being passed to the filesystem parser.
Actual Behavior
Fails with the error:
File "Q:\StableDiffusion\ComfyUI_windows_portable\ComfyUI\folder_paths.py", line 404, in get_save_image_path
os.makedirs(full_output_folder, exist_ok=True)
File "
Steps to Reproduce
Copied the exact text from the filename_prefix field into a PrimitiveString node, and it fails with the error.
Debug Logs
File "Q:\StableDiffusion\ComfyUI_windows_portable\ComfyUI\folder_paths.py", line 404, in get_save_image_path
os.makedirs(full_output_folder, exist_ok=True)
File "<frozen os>", line 225, in makedirs
NotADirectoryError: [WinError 267] The directory name is invalid: 'Q:\\StableDiffusion\\ComfyUI_windows_portable\\ComfyUI\\output\\WanVideo_Output-%date:yyyy-MM-dd%'
Other
No response
This happens with me as well.
I looked at the code used in nodes.py. Within the SaveImage class, it calls a function called folder_paths.get_save_image_path to assign the variable filename_prefix. This variable is used to make dirs from the os, which causes this error. This is where the string is resolved according to the error message trace in the console, so the problematic code to look at is within folder_paths.py. Here is the relevant code within the function:
def compute_vars(input: str, image_width: int, image_height: int) -> str:
input = input.replace("%width%", str(image_width))
input = input.replace("%height%", str(image_height))
now = time.localtime()
input = input.replace("%year%", str(now.tm_year))
input = input.replace("%month%", str(now.tm_mon).zfill(2))
input = input.replace("%day%", str(now.tm_mday).zfill(2))
input = input.replace("%hour%", str(now.tm_hour).zfill(2))
input = input.replace("%minute%", str(now.tm_min).zfill(2))
input = input.replace("%second%", str(now.tm_sec).zfill(2))
return input
if "%" in filename_prefix:
filename_prefix = compute_vars(filename_prefix, image_width, image_height)
Since the date is passed as %date:MM-dd-yyyy% (or some variation thereof), the replacement of the date would not happen by the above code called by 'save_images'. I'm not sure of an elegant way to code this as a hobbyist programmer, but I partially fixed it in my ComfyUI by adding the code below to the "compute_vars" function:
start = input.find("%date:")
if start == -1:
return input
end = input.find("%", start + 1)
if end == -1:
return input
subInput:str = input[start + len("%date:"):end]
subInput = subInput.replace("dd", str(now.tm_mday).zfill(2))
subInput = subInput.replace("MM", str(now.tm_mon).zfill(2))
subInput = subInput.replace("yyyy", str(now.tm_year))
subInput = subInput.replace("hh", str(now.tm_hour).zfill(2))
subInput = subInput.replace("mm", str(now.tm_min).zfill(2))
subInput = subInput.replace("ss", str(now.tm_sec).zfill(2))
input = input.replace(input[start:end+1], subInput)
return input
This solution however is limited as it does not replace the values as searched for by nodes like default. Unfortunately, I could not find the code that does this function natively within comfyUi. But theoretically, all you'd need to do in order to fix this bug would be to fix this "compute_vars" function with the function normally used for search and replace in comfyUI.
I ended up replacing the date string with the ones defined in that block you mentioned. Not sure where the original datestring is parsed.