receyuki / comfyui-prompt-reader-node

The ultimate solution for managing image metadata and multi-tool compatibility. ComfyUI node version of the SD Prompt Reader
MIT License
289 stars 22 forks source link

[BUG] - %counter fails to return the (last number in the folder (+1)) #56

Closed Dachiko closed 8 months ago

Dachiko commented 9 months ago

Description

Not sure how exactly it works. I have a folder with a lot of images, all of them have a leading number (the first file is like "05951 xyz.png" and the last one "105951 xyz.png"). There are gaps between file numbers (I delete images I don't like).

I expect %counter to return a number 105952, which is the last leading number in the folder.

Instead It returns some arbitrary number like 07040, and occasionally 07040_1 and 07040_2.

Basically I'd like to have fresh generations at the end of the file list.

Reproduction steps

No response

Image file

image image

Dachiko commented 9 months ago

Just want to add that ImageSave node works flawlessly, maybe you could steal the code from it :)

receyuki commented 9 months ago

This %counter is slightly different from the %counter in the built-in Saver node, it will count all image files in the path.

That means you already have 7,039 images in your folder.

Is the ImageSave node you mentioned a built-in node? If not, please tell me which specific node set it belongs to.

Dachiko commented 9 months ago

This %counter is slightly different from the %counter in the built-in Saver node, it will count all image files in the path.

That means you already have 7,039 images in your folder.

Is the ImageSave node you mentioned a built-in node? If not, please tell me which specific node set it belongs to.

It's some third-party node, but I'm not sure how to check the identity.

UPD It looks like it's a WASnodesuit node

receyuki commented 8 months ago

I just read the source code of image save, it seems to only support a fixed file name format, such as prefix + separator + number, or vice versa. Prompt saver supports many placeholders and can adjust their positions arbitrarily, so its handling of file names is much more complicated than image save. Therefore, I may not be able to achieve the effect you want.

Dachiko commented 8 months ago

I would appreciate if you'd make a conditional logic for the case when number is the leading placeholder. It just looses it's value in case when part of the files removed from the folder. But anyway, thank you for your work!

receyuki commented 8 months ago

I rethought it, and I think the problem is here: most people don't use just serial numbers as filenames like you do. So, should the serial number continue when other parts of the filename (such as %time) change? Or should it be considered as a new set of serial numbers? What if all parts of the filename apart from %counter are changed? Therefore, I think the current method (calculating the total number of files in the folder) is the most conservative one.

receyuki commented 8 months ago

Another approach is, you can use a separate node to record the sequence number of the image, and use it as the filename (or concate it with other strings) to input into the saver.

receyuki commented 8 months ago

Like this one

截屏2024-02-27 上午4 22 54
receyuki commented 8 months ago

Everything comes from WAS Node Suite.

Dachiko commented 8 months ago

I rethought it, and I think the problem is here: most people don't use just serial numbers as filenames like you do. So, should the serial number continue when other parts of the filename (such as %time) change? Or should it be considered as a new set of serial numbers? What if all parts of the filename apart from %counter are changed? Therefore, I think the current method (calculating the total number of files in the folder) is the most conservative one.

Thanks for the workaround, but it's too complicated to use in multiple workflows or across different backends. The practice I use comes from A1111. I always had it as a leading number + prompt / model name. It was quite a long time ago, so I don't remember, but I think it was a default naming convention. Not sure what convention people use usually. Maybe I should use date as a leading part, it could probably allow me to still have the latest generations at the end of the list. I liked to use simple number because it worked the same no matter what backend I used, my images were always in perfect order.